fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / OpenFlight / OSGOFAncillaryRecords.cpp
blobbf4702f3ec9d565662f823527fe7b31bc08a485a
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2011 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
30 #include "OSGOFAncillaryRecords.h"
32 #include "OSGImageFileHandler.h"
33 #include "OSGNameAttachment.h"
34 #include "OSGTransform.h"
35 #include "OSGOFDatabase.h"
36 #include "OSGOpenFlightLog.h"
37 #include "OSGPathHandler.h"
39 OSG_BEGIN_NAMESPACE
41 //---------------------------------------------------------------------
42 // OFColorPaletteRecord
43 //---------------------------------------------------------------------
45 /* static */
46 OFRecordTransitPtr OFColorPaletteRecord::create(const OFRecordHeader &oHeader,
47 OFDatabase &oDB )
49 return OFRecordTransitPtr(new OFColorPaletteRecord(oHeader, oDB));
52 OFColorPaletteRecord::OFColorPaletteRecord(const OFRecordHeader &oHeader,
53 OFDatabase &oDB ) :
54 Inherited (oHeader, oDB),
55 colors (),
56 colorNames()
60 /* virtual */
61 OFColorPaletteRecord::~OFColorPaletteRecord(void)
65 /* virtual */
66 bool OFColorPaletteRecord::read(std::istream &is)
68 OSG_OPENFLIGHT_LOG(("OFColorPaletteRecord::read len [%u]\n", _sLength));
70 Char8 reserved1[128];
71 Inherited::readChar8(is, reserved1, 128);
73 bool bHasNames = _sLength > 4228;
74 UInt32 numColors = 1024;
76 if(bHasNames == false)
78 // number of colors derived from record size
79 UInt32 numColors2 = (_sLength - 132) / 4;
81 numColors = osgMin(numColors, numColors2);
84 for(UInt32 i = 0; i < numColors; ++i)
86 UChar8 alpha;
87 UChar8 blue;
88 UChar8 green;
89 UChar8 red;
91 Inherited::readVal(is, alpha);
92 Inherited::readVal(is, blue );
93 Inherited::readVal(is, green);
94 Inherited::readVal(is, red );
96 colors.push_back(Color4f(red / 255.f, green / 255.f,
97 blue / 255.f, alpha / 255.f ));
100 if(bHasNames == true)
102 colorNames.resize(numColors);
104 Int32 numNames;
105 Inherited::readVal(is, numNames);
107 for(Int32 i = 0; i < numNames; ++i)
109 UInt16 nameLen;
110 Int16 reserved2;
111 Int16 colorIdx;
112 Int16 reserved3;
113 Char8 name[80];
115 Inherited::readVal (is, nameLen);
116 Inherited::readVal (is, reserved2);
117 Inherited::readVal (is, colorIdx);
118 Inherited::readVal (is, reserved3);
119 Inherited::readChar8(is, name, 80);
121 colorNames[colorIdx] = std::string(name);
125 return is.good();
128 /* virtual */
129 UInt16 OFColorPaletteRecord::getOpCode(void) const
131 return OpCode;
134 /* virtual */
135 void OFColorPaletteRecord::dump(UInt32 uiIndent) const
137 indentLog(uiIndent, PLOG);
138 PLOG << "ColorPaletteRecord" << std::endl;
140 indentLog(uiIndent, PLOG);
141 PLOG << "{" << std::endl;
143 uiIndent += 2;
145 for(UInt32 i = 0; i < colors.size(); ++i)
147 indentLog(uiIndent, PLOG);
148 PLOG << "Color " << colors[i];
150 if(colorNames.empty() == false)
151 PLOG << " name " << colorNames[i];
153 PLOG << std::endl;
156 uiIndent -= 2;
158 indentLog(uiIndent, PLOG);
159 PLOG << "}" << std::endl;
162 Color4f OFColorPaletteRecord::getColor(UInt32 uiIdx) const
164 Color4f returnValue;
165 UInt32 uiRealIdx = uiIdx >> 7;
166 Real32 intensity = (uiIdx & 0x7f) / 127.f;
168 OSG_ASSERT(uiRealIdx < colors.size());
170 returnValue = colors[uiRealIdx];
171 returnValue[0] *= intensity;
172 returnValue[1] *= intensity;
173 returnValue[2] *= intensity;
175 return returnValue;
178 bool OFColorPaletteRecord::hasNames(void) const
180 return !colorNames.empty();
183 std::string const &OFColorPaletteRecord::getName(UInt32 uiIdx) const
185 return colorNames[uiIdx];
188 OFRecordFactoryBase::RegisterRecord OFColorPaletteRecord::_regHelper(
189 &OFColorPaletteRecord::create,
190 OFColorPaletteRecord::OpCode);
192 //---------------------------------------------------------------------
193 // OFTexturePaletteRecord
194 //---------------------------------------------------------------------
196 GLenum OFTexturePaletteRecord::TexAttr::getMinFilter(void)
198 GLenum returnValue = GL_NEAREST;
200 switch(minFilter)
202 case 0: returnValue = GL_NEAREST; break; // point
203 case 1: returnValue = GL_LINEAR; break; // bilinear
204 case 3: returnValue = GL_NEAREST_MIPMAP_NEAREST; break; // mipmap point
205 case 4: returnValue = GL_NEAREST_MIPMAP_LINEAR; break; // mipmap linear
206 case 5: returnValue = GL_LINEAR_MIPMAP_NEAREST; break; // mipmap bilinear
207 case 7: returnValue = GL_LINEAR_MIPMAP_LINEAR; break; // mipmap trilinear
209 case 9: // bicubic
210 case 10: // bilinear GEQ
211 case 11: // bilinear LEQ
212 case 12: // bicubic GEQ
213 case 13: // bicubic LEQ
214 returnValue = GL_LINEAR_MIPMAP_NEAREST;
215 break;
217 default: returnValue = GL_LINEAR_MIPMAP_LINEAR; break;
220 return returnValue;
223 GLenum OFTexturePaletteRecord::TexAttr::getMagFilter(void)
225 GLenum returnValue = GL_NEAREST;
227 switch(magFilter)
229 case 0: returnValue = GL_NEAREST; break; // point
231 case 1: // bilinear
232 case 3: // bicubic
233 case 4: // sharpen
234 case 5: // add detail
235 case 6: // modulate detail
236 case 7: // bilinear GEQ
237 case 8: // bilinear LEQ
238 case 9: // bicubic GEQ
239 case 10: // bicubic LEQ
240 returnValue = GL_LINEAR;
241 break;
244 return returnValue;
247 GLenum OFTexturePaletteRecord::TexAttr::getWrapU(void)
249 return getWrap(wrapU);
252 GLenum OFTexturePaletteRecord::TexAttr::getWrapV(void)
254 return getWrap(wrapV);
257 GLenum OFTexturePaletteRecord::TexAttr::getEnvMode(void)
259 GLenum returnValue = GL_MODULATE;
261 switch(envMode)
263 case 0: returnValue = GL_MODULATE; break; // modulate
264 case 1: returnValue = GL_BLEND; break; // blend
265 case 2: returnValue = GL_DECAL; break; // decal
266 case 3: returnValue = GL_REPLACE; break; // replace
267 case 4: returnValue = GL_ADD; break; // add
270 return returnValue;
273 GLenum OFTexturePaletteRecord::TexAttr::getWrap(Int32 wrap)
275 GLenum returnValue = GL_REPEAT;
277 switch(wrap)
279 case 0: returnValue = GL_REPEAT; break; // repeat
280 case 1: returnValue = GL_CLAMP_TO_EDGE; break; // clamp
281 case 4: returnValue = GL_REPEAT; break; // mirror
284 return returnValue;
287 /* static */
288 OFRecordTransitPtr OFTexturePaletteRecord::create(const OFRecordHeader &oHeader,
289 OFDatabase &oDB )
291 return OFRecordTransitPtr(new OFTexturePaletteRecord(oHeader, oDB));
294 bool OFTexturePaletteRecord::readTexAttr(TexAttr &attr)
296 bool returnValue = false;
297 PathHandler *ph = ImageFileHandler::the()->getPathHandler();
299 if(ph != NULL)
301 std::string imgFile = szFilename;
302 std::string attrFile = imgFile + ".attr";
304 attrFile = ph->findFile(attrFile.c_str());
306 if(attrFile.empty() == false)
308 OSG_OPENFLIGHT_LOG(("OFTexturePaletteRecord::readTexAttr: [%s]\n",
309 attrFile.c_str()));
311 std::ifstream ifs;
312 ifs.open(attrFile.c_str(), std::ios::in | std::ios::binary);
314 Inherited::readVal(ifs, attr.numTexelU);
315 Inherited::readVal(ifs, attr.numTexelV);
316 Inherited::readVal(ifs, attr.realSizeU);
317 Inherited::readVal(ifs, attr.realSizeV);
318 Inherited::readVal(ifs, attr.upX);
319 Inherited::readVal(ifs, attr.upY);
320 Inherited::readVal(ifs, attr.fileFormat);
321 Inherited::readVal(ifs, attr.minFilter);
322 Inherited::readVal(ifs, attr.magFilter);
323 Inherited::readVal(ifs, attr.wrapUV);
324 Inherited::readVal(ifs, attr.wrapU);
325 Inherited::readVal(ifs, attr.wrapV);
326 Inherited::readVal(ifs, attr.modified);
327 Inherited::readVal(ifs, attr.pivotX);
328 Inherited::readVal(ifs, attr.pivotY);
329 Inherited::readVal(ifs, attr.envMode);
331 if(attr.wrapU == 3)
332 attr.wrapU = attr.wrapUV;
333 if(attr.wrapV == 3)
334 attr.wrapV = attr.wrapUV;
336 returnValue = true;
340 return returnValue;
343 OFTexturePaletteRecord::OFTexturePaletteRecord(const OFRecordHeader &oHeader,
344 OFDatabase &oDB ) :
345 Inherited (oHeader,
346 oDB ),
347 iPatternIdx(0 ),
348 iPatternX (0 ),
349 iPatternY (0 ),
350 pTexObj ( ),
351 pTexEnv ( )
355 OFTexturePaletteRecord::~OFTexturePaletteRecord(void)
357 pTexObj = NULL;
360 /* virtual */
361 bool OFTexturePaletteRecord::read(std::istream &is)
363 Inherited::readChar8(is, szFilename, 200);
364 Inherited::readVal (is, iPatternIdx );
365 Inherited::readVal (is, iPatternX );
366 Inherited::readVal (is, iPatternY );
368 OSG_OPENFLIGHT_LOG(("OFTexturePaletteRecord::read len "
369 "[%u] file [%s] idx [%d]\n",
370 _sLength, szFilename, iPatternIdx));
372 ImageUnrecPtr pImage = ImageFileHandler::the()->read(szFilename);
374 if(pImage != NULL)
376 pTexObj = TextureObjChunk::create();
378 pTexObj->setImage(pImage);
380 else
382 std::string szTmp = szFilename;
384 std::string::size_type uiPos = szTmp.rfind('/');
386 if(uiPos != std::string::npos)
388 pImage = ImageFileHandler::the()->read(
389 &(szFilename[uiPos + 1]));
391 if(pImage != NULL)
393 pTexObj = TextureObjChunk::create();
395 pTexObj->setImage(pImage);
397 else
399 FWARNING(("OFTexturePaletteRecord::read: Could not read image "
400 "[%s].\n", &(szFilename[uiPos + 1])));
403 else
405 FWARNING(("OFTexturePaletteRecord::read: Could not read image "
406 "[%s].\n", szFilename));
410 if(pTexObj != NULL)
412 TexAttr attr;
413 if(readTexAttr(attr) == true)
415 pTexObj->setMinFilter(attr.getMinFilter());
416 pTexObj->setMagFilter(attr.getMagFilter());
417 pTexObj->setWrapS (attr.getWrapU ());
418 pTexObj->setWrapT (attr.getWrapV ());
420 pTexEnv = TextureEnvChunk::create();
421 pTexEnv->setEnvMode(attr.getEnvMode());
425 return is.good();
428 /* virtual */
429 UInt16 OFTexturePaletteRecord::getOpCode(void) const
431 return OpCode;
434 void OFTexturePaletteRecord::dump(UInt32 uiIndent) const
436 indentLog(uiIndent, PLOG);
437 PLOG << "TexturePaletteRecord" << std::endl;
439 indentLog(uiIndent, PLOG);
440 PLOG << "{" << std::endl;
442 uiIndent += 2;
444 indentLog(uiIndent, PLOG);
445 PLOG << "Filename : " << szFilename << std::endl;
447 indentLog(uiIndent, PLOG);
448 PLOG << "PatternIdx : " << iPatternIdx << std::endl;
450 indentLog(uiIndent, PLOG);
451 PLOG << "PatternX : " << iPatternX << std::endl;
453 indentLog(uiIndent, PLOG);
454 PLOG << "PatternY : " << iPatternY << std::endl;
456 uiIndent -= 2;
458 indentLog(uiIndent, PLOG);
459 PLOG << "}" << std::endl;
462 Int32 OFTexturePaletteRecord::getPatternIdx(void)
464 return iPatternIdx;
467 TextureObjChunk *OFTexturePaletteRecord::getTexObj(void) const
469 return pTexObj;
472 TextureEnvChunk *OFTexturePaletteRecord::getTexEnv(void) const
474 return pTexEnv;
477 OFRecordFactoryBase::RegisterRecord OFTexturePaletteRecord::_regHelper(
478 &OFTexturePaletteRecord::create,
479 OFTexturePaletteRecord::OpCode);
481 //---------------------------------------------------------------------
482 // OFVertexPaletteRecord
483 //---------------------------------------------------------------------
485 OFRecordTransitPtr OFVertexPaletteRecord::create(const OFRecordHeader &oHeader,
486 OFDatabase &oDB )
488 return OFRecordTransitPtr(new OFVertexPaletteRecord(oHeader, oDB));
491 OFVertexPaletteRecord::OFVertexPaletteRecord(const OFRecordHeader &oHeader,
492 OFDatabase &oDB ) :
493 Inherited (oHeader,
494 oDB ),
495 vPositions ( ),
496 vNormals ( ),
497 vTexCoords ( ),
498 vVertexInfo( )
502 OFVertexPaletteRecord::~OFVertexPaletteRecord(void)
506 bool OFVertexPaletteRecord::read(std::istream &is)
508 OSG_OPENFLIGHT_LOG(("OFVertexPaletteRecord::read len [%u]\n",
509 _sLength));
511 static std::vector<char> tmpBuf;
513 Int32 iFullLength;
514 Inherited::readVal(is, iFullLength);
516 Int32 iRead = 0;
518 OFRecordHeader oRHeader;
519 bool rc = true;
520 Vec3d tmpPos;
521 Vec3f tmpNorm;
522 Vec2f tmpTexCoord;
523 VertexInfo tmpInfo;
525 while(iRead < iFullLength - 8 && is.good() == true)
527 rc = oRHeader.read(is);
529 if(rc == false)
531 break;
534 tmpInfo.uiType = HasPos | HasCol;
535 tmpInfo.uiOffset = iRead + 8;
537 tmpInfo.uiIdx[ColIdx ] = -1;
538 tmpInfo.uiIdx[NormIdx ] = -1;
539 tmpInfo.uiIdx[TexCoordIdx] = -1;
541 Int32 uiSize = 0;
543 uiSize += Inherited::readVal(is, tmpInfo.uiColNameIdx);
544 uiSize += Inherited::readVal(is, tmpInfo.iFlags );
546 uiSize += Inherited::readVal(is, tmpPos[0]);
547 uiSize += Inherited::readVal(is, tmpPos[1]);
548 uiSize += Inherited::readVal(is, tmpPos[2]);
550 tmpPos *= _oDB.getUnitScale();
552 tmpInfo.uiIdx[PosIdx] = UInt32(vPositions.size());
554 vPositions.push_back(Pnt3f(tmpPos));
556 if(oRHeader.sOpCode == 69 || oRHeader.sOpCode == 70)
558 uiSize += Inherited::readVal(is, tmpNorm[0]);
559 uiSize += Inherited::readVal(is, tmpNorm[1]);
560 uiSize += Inherited::readVal(is, tmpNorm[2]);
562 tmpInfo.uiIdx[NormIdx] = UInt32(vNormals.size());
563 tmpInfo.uiType |= HasNorm;
565 vNormals.push_back(tmpNorm);
568 if(oRHeader.sOpCode == 70 || oRHeader.sOpCode == 71)
570 uiSize += Inherited::readVal(is, tmpTexCoord[0]);
571 uiSize += Inherited::readVal(is, tmpTexCoord[1]);
573 tmpInfo.uiIdx[TexCoordIdx] = UInt32(vTexCoords.size());
574 tmpInfo.uiType |= HasTexCoord;
576 vTexCoords.push_back(tmpTexCoord);
579 uiSize += Inherited::readVal(is, tmpInfo.iPackedCol);
580 uiSize += Inherited::readVal(is, tmpInfo.iColIdx );
582 if(oRHeader.sOpCode == 69 || oRHeader.sOpCode == 70)
584 if(uiSize < oRHeader.sLength - 4)
586 uiSize += Inherited::readVal(is, tmpInfo.iPad1);
590 vVertexInfo.push_back(tmpInfo);
592 iRead += oRHeader.sLength;
595 #if 0
596 fprintf(stderr, "Got %d vertices\n",
597 vVertexInfo.size());
598 #endif
600 return is.good();
603 UInt16 OFVertexPaletteRecord::getOpCode(void) const
605 return OpCode;
608 const OFVertexPaletteRecord::VertexInfo *
609 OFVertexPaletteRecord::getVertexInfo(UInt32 uiOff) const
611 std::vector<VertexInfo>::const_iterator iLBound =
612 std::lower_bound(vVertexInfo.begin(),
613 vVertexInfo.end (),
614 uiOff);
616 if(iLBound != vVertexInfo.end())
618 return &(*iLBound);
621 return NULL;
624 const Pnt3f &OFVertexPaletteRecord::getPos(UInt32 uiIdx) const
626 OSG_ASSERT(uiIdx < vPositions.size());
628 return vPositions[uiIdx];
631 const Vec3f &OFVertexPaletteRecord::getNormal(UInt32 uiIdx) const
633 OSG_ASSERT(uiIdx < vNormals.size());
635 return vNormals[uiIdx];
638 const Vec2f &OFVertexPaletteRecord::getTexCoord(UInt32 uiIdx) const
640 OSG_ASSERT(uiIdx < vTexCoords.size());
642 return vTexCoords[uiIdx];
645 bool OFVertexPaletteRecord::VertexInfo::operator <(const UInt32 uiOff) const
647 return this->uiOffset < uiOff;
650 bool OFVertexPaletteRecord::VertexInfo::operator <(
651 const VertexInfo &vInfo) const
653 return this->uiOffset < vInfo.uiOffset;
656 bool operator <(const UInt32 uiOff,
657 const OFVertexPaletteRecord::VertexInfo &vInfo)
659 return uiOff < vInfo.uiOffset;
662 OFRecordFactoryBase::RegisterRecord OFVertexPaletteRecord::_regHelper(
663 &OFVertexPaletteRecord::create,
664 OFVertexPaletteRecord::OpCode);
667 //---------------------------------------------------------------------
668 // OFMaterialPaletteRecord
669 //---------------------------------------------------------------------
671 OFMaterialPaletteRecord::OFMaterialPaletteRecord(
672 const OFRecordHeader &oHeader,
673 OFDatabase &oDB ) :
675 Inherited (oHeader,
676 oDB ),
677 iMaterialIdx(0 ),
678 iFlags (0 ),
681 colAmbient ( ),
682 colDiffuse ( ),
683 colSpecular ( ),
684 colEmissive ( ),
685 fShininess (0.0 ),
686 fAlpha (0.0 ),
687 iPad (0 )
690 // nothing to do
693 OFMaterialPaletteRecord::~OFMaterialPaletteRecord(void)
695 // nothing to do
698 OFRecordTransitPtr OFMaterialPaletteRecord::create(
699 const OFRecordHeader &oHeader, OFDatabase &oDB)
701 return OFRecordTransitPtr(new OFMaterialPaletteRecord(oHeader, oDB));
704 bool OFMaterialPaletteRecord::read(std::istream &is)
706 OSG_OPENFLIGHT_LOG(("OFMaterialPaletteRecord::read len [%u]\n",
707 _sLength));
709 Inherited::readVal (is, iMaterialIdx );
710 Inherited::readChar8(is, szMaterialName, 12);
711 Inherited::readVal (is, iFlags );
712 Inherited::readVal (is, colAmbient[0] );
713 Inherited::readVal (is, colAmbient[1] );
714 Inherited::readVal (is, colAmbient[2] );
715 Inherited::readVal (is, colDiffuse[0] );
716 Inherited::readVal (is, colDiffuse[1] );
717 Inherited::readVal (is, colDiffuse[2] );
718 Inherited::readVal (is, colSpecular[0] );
719 Inherited::readVal (is, colSpecular[1] );
720 Inherited::readVal (is, colSpecular[2] );
721 Inherited::readVal (is, colEmissive[0] );
722 Inherited::readVal (is, colEmissive[1] );
723 Inherited::readVal (is, colEmissive[2] );
724 Inherited::readVal (is, fShininess );
725 Inherited::readVal (is, fAlpha );
726 Inherited::readVal (is, iPad );
728 return is.good();
731 UInt16 OFMaterialPaletteRecord::getOpCode(void) const
733 return OpCode;
736 void OFMaterialPaletteRecord::dump(UInt32 uiIndent) const
738 indentLog(uiIndent, PLOG);
739 PLOG << "OFMaterialPaletteRecord : " << std::endl;
741 indentLog(uiIndent, PLOG);
742 PLOG << "{" << std::endl;
744 uiIndent += 2;
746 indentLog(uiIndent, PLOG);
747 PLOG << "MaterialIdx : " << iMaterialIdx << std::endl;
749 indentLog(uiIndent, PLOG);
750 PLOG << "MaterialName : " << szMaterialName << std::endl;
752 indentLog(uiIndent, PLOG);
753 PLOG << "ColAmbient : " << colAmbient << std::endl;
755 indentLog(uiIndent, PLOG);
756 PLOG << "ColDiffuse : " << colDiffuse << std::endl;
758 indentLog(uiIndent, PLOG);
759 PLOG << "ColSpecular : " << colSpecular << std::endl;
761 indentLog(uiIndent, PLOG);
762 PLOG << "ColEmissive : " << colEmissive << std::endl;
764 indentLog(uiIndent, PLOG);
765 PLOG << "Shininess : " << fShininess << std::endl;
767 indentLog(uiIndent, PLOG);
768 PLOG << "Alpha : " << fAlpha << std::endl;
770 uiIndent -= 2;
772 indentLog(uiIndent, PLOG);
773 PLOG << "}" << std::endl;
776 Int32 OFMaterialPaletteRecord::getMaterialIdx(void)
778 return iMaterialIdx;
781 const Color4f &OFMaterialPaletteRecord::getAmbient(void) const
783 return colAmbient;
786 const Color4f &OFMaterialPaletteRecord::getDiffuse(void) const
788 return colDiffuse;
791 const Color4f &OFMaterialPaletteRecord::getSpecular(void) const
793 return colSpecular;
796 const Color4f &OFMaterialPaletteRecord::getEmissive(void) const
798 return colEmissive;
801 Real32 OFMaterialPaletteRecord::getShininess(void) const
803 return fShininess;
806 Real32 OFMaterialPaletteRecord::getAlpha(void) const
808 return fAlpha;
811 OFRecordFactoryBase::RegisterRecord OFMaterialPaletteRecord::_regHelper(
812 &OFMaterialPaletteRecord::create,
813 OFMaterialPaletteRecord::OpCode);
815 //---------------------------------------------------------------------
816 // OFMatrixRecord
817 //---------------------------------------------------------------------
819 /* static */
820 OFRecordTransitPtr OFMatrixRecord::create(const OFRecordHeader &oHeader,
821 OFDatabase &oDB )
823 return OFRecordTransitPtr(new OFMatrixRecord(oHeader, oDB));
826 OFMatrixRecord::OFMatrixRecord(const OFRecordHeader &oHeader,
827 OFDatabase &oDB ) :
828 Inherited(oHeader, oDB),
829 matrix ()
833 /* virtual */
834 OFMatrixRecord::~OFMatrixRecord(void)
838 /* virtual */
839 bool OFMatrixRecord::read(std::istream &is)
841 OSG_OPENFLIGHT_LOG(("OFMatrixRecord::read len [%u]\n", _sLength));
843 Inherited::readVal(is, matrix[0][0]);
844 Inherited::readVal(is, matrix[0][1]);
845 Inherited::readVal(is, matrix[0][2]);
846 Inherited::readVal(is, matrix[0][3]);
848 Inherited::readVal(is, matrix[1][0]);
849 Inherited::readVal(is, matrix[1][1]);
850 Inherited::readVal(is, matrix[1][2]);
851 Inherited::readVal(is, matrix[1][3]);
853 Inherited::readVal(is, matrix[2][0]);
854 Inherited::readVal(is, matrix[2][1]);
855 Inherited::readVal(is, matrix[2][2]);
856 Inherited::readVal(is, matrix[2][3]);
858 Inherited::readVal(is, matrix[3][0]);
859 Inherited::readVal(is, matrix[3][1]);
860 Inherited::readVal(is, matrix[3][2]);
861 Inherited::readVal(is, matrix[3][3]);
863 matrix[3][0] *= _oDB.getUnitScale();
864 matrix[3][1] *= _oDB.getUnitScale();
865 matrix[3][2] *= _oDB.getUnitScale();
867 return is.good();
870 /* virtual */
871 UInt16 OFMatrixRecord::getOpCode(void) const
873 return OpCode;
876 /* virtual */
877 void OFMatrixRecord::dump(UInt32 uiIndent) const
879 indentLog(uiIndent, PLOG);
880 PLOG << "MatrixRecord" << std::endl;
882 indentLog(uiIndent, PLOG);
883 PLOG << "{" << std::endl;
885 uiIndent += 2;
887 indentLog(uiIndent, PLOG);
888 PLOG << matrix[0][0] << " " << matrix[1][0] << " "
889 << matrix[2][0] << " " << matrix[3][0] << std::endl;
891 indentLog(uiIndent, PLOG);
892 PLOG << matrix[0][1] << " " << matrix[1][1] << " "
893 << matrix[2][1] << " " << matrix[3][1] << std::endl;
895 indentLog(uiIndent, PLOG);
896 PLOG << matrix[0][2] << " " << matrix[1][2] << " "
897 << matrix[2][2] << " " << matrix[3][2] << std::endl;
899 indentLog(uiIndent, PLOG);
900 PLOG << matrix[0][3] << " " << matrix[1][3] << " "
901 << matrix[2][3] << " " << matrix[3][3] << std::endl;
903 uiIndent -= 2;
905 indentLog(uiIndent, PLOG);
906 PLOG << "}" << std::endl;
908 Inherited::dump(uiIndent);
911 /* virtual */
912 NodeTransitPtr OFMatrixRecord::convert(Node *pNode)
914 NodeUnrecPtr returnValue(NULL);
916 if(pNode != NULL)
918 TransformUnrecPtr pXform = Transform::create();
919 pXform->setMatrix(matrix);
921 returnValue = makeNodeFor(pXform);
922 returnValue->addChild(pNode);
925 return NodeTransitPtr(returnValue);
928 OFRecordFactoryBase::RegisterRecord OFMatrixRecord::_regHelper(
929 &OFMatrixRecord::create,
930 OFMatrixRecord::OpCode);
932 //---------------------------------------------------------------------
933 // OFIgnoredTransformRecord
934 //---------------------------------------------------------------------
936 /* static */
937 OFRecordTransitPtr OFIgnoredTransformRecord::create(
938 const OFRecordHeader &oHeader,
939 OFDatabase &oDB )
941 return OFRecordTransitPtr(new OFIgnoredTransformRecord(oHeader, oDB));
944 OFIgnoredTransformRecord::OFIgnoredTransformRecord(
945 const OFRecordHeader &oHeader,
946 OFDatabase &oDB ) :
948 Inherited(oHeader, oDB),
949 _sOpCode (oHeader.sOpCode)
953 /* virtual */
954 OFIgnoredTransformRecord::~OFIgnoredTransformRecord(void)
958 /* virtual */
959 bool OFIgnoredTransformRecord::read(std::istream &is)
961 OSG_OPENFLIGHT_LOG(("OFIgnoredTransformRecord::read op [%u][%s] len [%u]\n",
962 _sOpCode, getOpCodeString(_sOpCode), _sLength));
964 static std::vector<char> tmpBuf;
966 if(_sLength > 4)
968 tmpBuf.resize(_sLength);
970 is.read(&(tmpBuf.front()), _sLength - 4);
973 return is.good();
976 /* virtual */
977 NodeTransitPtr OFIgnoredTransformRecord::convert(Node *pNode)
979 return NodeTransitPtr(pNode);
982 /* virtual */
983 UInt16 OFIgnoredTransformRecord::getOpCode(void) const
985 return _sOpCode;
988 /* virtual */
989 void OFIgnoredTransformRecord::dump(UInt32 uiIndent) const
991 indentLog(uiIndent, PLOG);
992 PLOG << "OFIgnoredTransformRecord - " << _sOpCode
993 << " - " << getOpCodeString(_sOpCode)
994 << std::endl;
997 OFRecordFactoryBase::RegisterRecord
998 OFIgnoredTransformRecord::_regHelperRotateAboutEdge(
999 &OFIgnoredTransformRecord::create,
1000 OFIgnoredTransformRecord::OpCodeRotateAboutEdge);
1002 OFRecordFactoryBase::RegisterRecord
1003 OFIgnoredTransformRecord::_regHelperTranslate(
1004 &OFIgnoredTransformRecord::create,
1005 OFIgnoredTransformRecord::OpCodeTranslate);
1007 OFRecordFactoryBase::RegisterRecord
1008 OFIgnoredTransformRecord::_regHelperScale(
1009 &OFIgnoredTransformRecord::create,
1010 OFIgnoredTransformRecord::OpCodeScale);
1012 OFRecordFactoryBase::RegisterRecord
1013 OFIgnoredTransformRecord::_regHelperRotateAboutPoint(
1014 &OFIgnoredTransformRecord::create,
1015 OFIgnoredTransformRecord::OpCodeRotateAboutPoint);
1017 OFRecordFactoryBase::RegisterRecord
1018 OFIgnoredTransformRecord::_regHelperRotateScaleToPoint(
1019 &OFIgnoredTransformRecord::create,
1020 OFIgnoredTransformRecord::OpCodeRotateScaleToPoint);
1022 OFRecordFactoryBase::RegisterRecord
1023 OFIgnoredTransformRecord::_regHelperPut(
1024 &OFIgnoredTransformRecord::create,
1025 OFIgnoredTransformRecord::OpCodePut);
1027 OFRecordFactoryBase::RegisterRecord
1028 OFIgnoredTransformRecord::_regHelperGeneralMatrix(
1029 &OFIgnoredTransformRecord::create,
1030 OFIgnoredTransformRecord::OpCodeGeneralMatrix);
1032 //---------------------------------------------------------------------
1033 // OFLongIDRecord
1034 //---------------------------------------------------------------------
1036 /* static */
1037 OFRecordTransitPtr OFLongIDRecord::create(const OFRecordHeader &oHeader,
1038 OFDatabase &oDB )
1040 return OFRecordTransitPtr(new OFLongIDRecord(oHeader, oDB));
1043 OFLongIDRecord::OFLongIDRecord(const OFRecordHeader &oHeader,
1044 OFDatabase &oDB ) :
1045 Inherited(oHeader, oDB),
1046 longId ()
1050 /* virtual */
1051 OFLongIDRecord::~OFLongIDRecord(void)
1055 /* virtual */
1056 bool OFLongIDRecord::read(std::istream &is)
1058 OSG_OPENFLIGHT_LOG(("OFLongIDRecord::read len [%u]\n", _sLength));
1060 longId.resize(_sLength - 4);
1061 is.read(reinterpret_cast<Char8 *>(&(*longId.begin())), _sLength - 4);
1063 return is.good();
1066 /* virtual */
1067 UInt16 OFLongIDRecord::getOpCode(void) const
1069 return OpCode;
1072 /* virtual */
1073 void OFLongIDRecord::dump(UInt32 uiIndent) const
1075 indentLog(uiIndent, PLOG);
1076 PLOG << "LongIDRecord" << std::endl;
1078 indentLog(uiIndent, PLOG);
1079 PLOG << "{" << std::endl;
1081 uiIndent += 2;
1083 indentLog(uiIndent, PLOG);
1084 PLOG << "longId: '" << longId << "'" << std::endl;
1086 uiIndent -= 2;
1088 indentLog(uiIndent, PLOG);
1089 PLOG << "}" << std::endl;
1091 Inherited::dump(uiIndent);
1094 /* virtual */
1095 NodeTransitPtr OFLongIDRecord::convert(Node *pNode)
1097 NodeUnrecPtr returnValue(pNode);
1099 if(pNode != NULL)
1101 setName(pNode, longId);
1104 return NodeTransitPtr(returnValue);
1107 OFRecordFactoryBase::RegisterRecord OFLongIDRecord::_regHelper(
1108 &OFLongIDRecord::create,
1109 OFLongIDRecord::OpCode);
1111 OSG_END_NAMESPACE