2
// Copyright (C) 1997 - 2001, Paul C. Gregory
4
// Contact: pgregory@aqsis.org
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation; either
9
// version 2 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
#include "micropolygon.h"
23
#include "bucketprocessor.h"
44
char filename[20] = "mpdump.mp";
45
int sf = sizeof(TqFloat);
49
m_outFile = fopen(filename, "wb");
52
Aqsis::log() << info << "Creating '" << filename << "'" << std::endl;
53
size_t len_written = fwrite((void*)&sf, sizeof(int), 1, m_outFile);
55
AQSIS_THROW_XQERROR(XqInvalidFile, EqE_System,
56
"Error writing mpdump file");
59
Aqsis::log() << error << "Could not create '" << filename << "'" << std::endl;
62
// Close the dump file
63
void CqMPDump::close()
69
Aqsis::log() << info << m_mpcount << " micro polygons dumped" << std::endl;
73
// Dump global information about the image
74
void CqMPDump::dumpImageInfo()
80
Aqsis::log() << error << "Attempted to write to unopened mpdump file." << std::endl;
84
int width = QGetRenderContext() ->poptCurrent()->GetIntegerOption( "System", "Resolution" ) [ 0 ];
85
int height = QGetRenderContext() ->poptCurrent()->GetIntegerOption( "System", "Resolution" ) [ 1 ];
86
size_t len_written = fwrite((void*)&id, sizeof(short), 1, m_outFile);
87
len_written += fwrite((void*)&width, sizeof(int), 1, m_outFile);
88
len_written += fwrite((void*)&height, sizeof(int), 1, m_outFile);
90
AQSIS_THROW_XQERROR(XqInvalidFile, EqE_System,
91
"Error writing mpdump file");
94
// Dump all pixel samples of the current bucket
95
void CqMPDump::dumpPixelSamples(const CqBucketProcessor& bp)
97
const std::vector<CqImagePixelPtr>& pixels = bp.pixels();
98
for(std::vector<CqImagePixelPtr>::const_iterator p = pixels.begin(),
99
e = pixels.end(); p != e; ++p)
101
const CqImagePixel& pixel = **p;
102
for(int i = 0, numSamples = pixel.numSamples(); i < numSamples; ++i)
104
CqVector2D pos = pixel.SampleData(i).position;
105
if(!( pos.x() <= bp.SampleRegion().xMin()
106
|| pos.x() > bp.SampleRegion().xMax()
107
|| pos.y() <= bp.SampleRegion().yMin()
108
|| pos.y() > bp.SampleRegion().yMax() ) )
110
// Only dump samples which are inside bp.SampleRegion()
111
// this means that only samples which are actually computed for
112
// the current bucket will be considered.
113
dump(lfloor(pos.x()), lfloor(pos.y()), i, pos);
119
// Dump a pixel sample
120
void CqMPDump::dump(int x, int y, int idx, const CqVector2D& pos)
127
Aqsis::log() << error << "Attempted to write to unopened mpdump file." << std::endl;
131
size_t len_written = fwrite((void*)&id, sizeof(short), 1, m_outFile);
132
len_written += fwrite((void*)&x, sizeof(int), 1, m_outFile);
133
len_written += fwrite((void*)&y, sizeof(int), 1, m_outFile);
134
len_written += fwrite((void*)&idx, sizeof(int), 1, m_outFile);
136
len_written += fwrite((void*)&f, sizeof(TqFloat), 1, m_outFile);
138
len_written += fwrite((void*)&f, sizeof(TqFloat), 1, m_outFile);
140
AQSIS_THROW_XQERROR(XqInvalidFile, EqE_System,
141
"Error writing mpdump file");
144
// Dump a micro polygon
145
void CqMPDump::dump(const CqMicroPolygon& mp)
152
Aqsis::log() << error << "Attempted to write to unopened mpdump file." << std::endl;
157
size_t len_written = fwrite((void*)&id, sizeof(short), 1, m_outFile);
159
AQSIS_THROW_XQERROR(XqInvalidFile, EqE_System,
160
"Error writing mpdump file");
162
// Dump vertices in a funny circular order for backward-compatibility
163
// rather than in the usual bilinear patch type order.
170
if (mp.pGrid()->pVar(EnvVars_Ci)!=NULL)
173
c = CqColor(0.9,0.9,1);
175
if (mp.pGrid()->pVar(EnvVars_Oi)!=NULL)
176
c = *mp.colOpacity();
178
c = CqColor(0.9,0.9,1);
183
void CqMPDump::dumpVec3(const CqVector3D& v)
189
size_t len_written = fwrite((void*)&x, sizeof(TqFloat), 1, m_outFile);
190
len_written += fwrite((void*)&y, sizeof(TqFloat), 1, m_outFile);
191
len_written += fwrite((void*)&z, sizeof(TqFloat), 1, m_outFile);
193
AQSIS_THROW_XQERROR(XqInvalidFile, EqE_System,
194
"Error writing mpdump file");
198
void CqMPDump::dumpCol(const CqColor& c)
204
size_t len_written = fwrite((void*)&r, sizeof(TqFloat), 1, m_outFile);
205
len_written += fwrite((void*)&g, sizeof(TqFloat), 1, m_outFile);
206
len_written += fwrite((void*)&b, sizeof(TqFloat), 1, m_outFile);
208
AQSIS_THROW_XQERROR(XqInvalidFile, EqE_System,
209
"Error writing mpdump file");
213
/// Global dump object