KiCad PCB EDA Suite
SGSHAPE Class Reference

Define a complex 3D shape for a scenegraph object. More...

#include <sg_shape.h>

Inheritance diagram for SGSHAPE:
SGNODE

Public Member Functions

 SGSHAPE (SGNODE *aParent)
 
virtual ~SGSHAPE ()
 
virtual bool SetParent (SGNODE *aParent, bool notify=true) override
 Set the parent SGNODE of this object. More...
 
SGNODEFindNode (const char *aNodeName, const SGNODE *aCaller) override
 Search the tree of linked nodes and return a reference to the first node found with the given name. More...
 
bool AddRefNode (SGNODE *aNode) override
 
bool AddChildNode (SGNODE *aNode) override
 
void ReNameNodes (void) override
 Rename a node and all its child nodes in preparation for write operations. More...
 
bool WriteVRML (std::ostream &aFile, bool aReuseFlag) override
 Writes this node's data to a VRML file. More...
 
bool WriteCache (std::ostream &aFile, SGNODE *parentNode) override
 Write this node's data to a binary cache file. More...
 
bool ReadCache (std::istream &aFile, SGNODE *parentNode) override
 Reads binary format data from a cache file. More...
 
bool Prepare (const glm::dmat4 *aTransform, S3D::MATLIST &materials, std::vector< SMESH > &meshes)
 
void unlinkChildNode (const SGNODE *aNode) override
 Remove references to an owned child. More...
 
void unlinkRefNode (const SGNODE *aNode) override
 Remove pointers to a referenced node. More...
 
S3D::SGTYPES GetNodeType (void) const noexcept
 Return the type of this node instance. More...
 
SGNODEGetParent (void) const noexcept
 Returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie. More...
 
bool SwapParent (SGNODE *aNewParent)
 Swap the ownership with the given parent. More...
 
const char * GetName (void)
 
void SetName (const char *aName)
 
const char * GetNodeTypeName (S3D::SGTYPES aNodeType) const noexcept
 
void AssociateWrapper (SGNODE **aWrapperRef) noexcept
 Associate this object with a handle to itself. More...
 
void DisassociateWrapper (SGNODE **aWrapperRef) noexcept
 Remove the association between an IFSG* wrapper object and this object. More...
 
void ResetNodeIndex (void) noexcept
 Reset the global SG* node indices in preparation for write operations. More...
 
void addNodeRef (SGNODE *aNode)
 Add a pointer to a node which references this node, but does not own. More...
 
void delNodeRef (const SGNODE *aNode)
 Remove a pointer to a node which references this node, but does not own. More...
 
bool isWritten (void) noexcept
 Return true if the object had already been written to a cache file or VRML file. More...
 

Public Attributes

SGAPPEARANCEm_Appearance
 
SGFACESETm_FaceSet
 
SGAPPEARANCEm_RAppearance
 
SGFACESETm_RFaceSet
 

Protected Attributes

std::list< SGNODE * > m_BackPointers
 nodes which hold a reference to this. More...
 
SGNODEm_Parent
 Pointer to parent node; may be NULL for top level transform. More...
 
S3D::SGTYPES m_SGtype
 Type of Scene Graph node. More...
 
std::string m_Name
 name to use for referencing the entity by name. More...
 
bool m_written
 Set to true when the object has been written after a ReNameNodes(). More...
 

Private Member Functions

void unlinkNode (const SGNODE *aNode, bool isChild)
 
bool addNode (SGNODE *aNode, bool isChild)
 

Detailed Description

Define a complex 3D shape for a scenegraph object.

Definition at line 42 of file sg_shape.h.

Constructor & Destructor Documentation

◆ SGSHAPE()

SGSHAPE::SGSHAPE ( SGNODE aParent)

Definition at line 40 of file sg_shape.cpp.

40  : SGNODE( aParent )
41 {
43  m_Appearance = nullptr;
44  m_RAppearance = nullptr;
45  m_FaceSet = nullptr;
46  m_RFaceSet = nullptr;
47 
48  if( nullptr != aParent && S3D::SGTYPE_TRANSFORM != aParent->GetNodeType() )
49  {
50  m_Parent = nullptr;
51 
52  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] inappropriate parent to SGSHAPE (type %d)",
53  __FILE__, __FUNCTION__, __LINE__, aParent->GetNodeType() );
54  }
55  else if( nullptr != aParent && S3D::SGTYPE_TRANSFORM == aParent->GetNodeType() )
56  {
57  m_Parent->AddChildNode( this );
58  }
59 }
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
SGFACESET * m_RFaceSet
Definition: sg_shape.h:77
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:72
SGFACESET * m_FaceSet
Definition: sg_shape.h:73
SGNODE(SGNODE *aParent)
Definition: sg_node.cpp:76
S3D::SGTYPES m_SGtype
Type of Scene Graph node.
Definition: sg_node.h:228
virtual bool AddChildNode(SGNODE *aNode)=0
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:76
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104

References SGNODE::AddChildNode(), SGNODE::GetNodeType(), m_Appearance, m_FaceSet, SGNODE::m_Parent, m_RAppearance, m_RFaceSet, SGNODE::m_SGtype, S3D::SGTYPE_SHAPE, and S3D::SGTYPE_TRANSFORM.

◆ ~SGSHAPE()

SGSHAPE::~SGSHAPE ( )
virtual

Definition at line 62 of file sg_shape.cpp.

63 {
64  // drop references
65  if( m_RAppearance )
66  {
67  m_RAppearance->delNodeRef( this );
68  m_RAppearance = nullptr;
69  }
70 
71  if( m_RFaceSet )
72  {
73  m_RFaceSet->delNodeRef( this );
74  m_RFaceSet = nullptr;
75  }
76 
77  // delete objects
78  if( m_Appearance )
79  {
80  m_Appearance->SetParent( nullptr, false );
81  delete m_Appearance;
82  m_Appearance = nullptr;
83  }
84 
85  if( m_FaceSet )
86  {
87  m_FaceSet->SetParent( nullptr, false );
88  delete m_FaceSet;
89  m_FaceSet = nullptr;
90  }
91 }
SGFACESET * m_RFaceSet
Definition: sg_shape.h:77
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Set the parent SGNODE of this object.
void delNodeRef(const SGNODE *aNode)
Remove a pointer to a node which references this node, but does not own.
Definition: sg_node.cpp:185
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:72
SGFACESET * m_FaceSet
Definition: sg_shape.h:73
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Set the parent SGNODE of this object.
Definition: sg_faceset.cpp:117
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:76

References SGNODE::delNodeRef(), m_Appearance, m_FaceSet, m_RAppearance, m_RFaceSet, SGAPPEARANCE::SetParent(), and SGFACESET::SetParent().

Member Function Documentation

◆ AddChildNode()

bool SGSHAPE::AddChildNode ( SGNODE aNode)
overridevirtual

Implements SGNODE.

Definition at line 290 of file sg_shape.cpp.

291 {
292  return addNode( aNode, true );
293 }
bool addNode(SGNODE *aNode, bool isChild)
Definition: sg_shape.cpp:215

References addNode().

◆ addNode()

bool SGSHAPE::addNode ( SGNODE aNode,
bool  isChild 
)
private

Definition at line 215 of file sg_shape.cpp.

216 {
217  wxCHECK( aNode, false );
218 
219  if( S3D::SGTYPE_APPEARANCE == aNode->GetNodeType() )
220  {
221  if( m_Appearance || m_RAppearance )
222  {
223  if( aNode != m_Appearance && aNode != m_RAppearance )
224  {
225  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] assigning multiple Appearance nodes",
226  __FILE__, __FUNCTION__, __LINE__ );
227 
228  return false;
229  }
230 
231  return true;
232  }
233 
234  if( isChild )
235  {
236  m_Appearance = (SGAPPEARANCE*)aNode;
237  m_Appearance->SetParent( this );
238  }
239  else
240  {
241  m_RAppearance = (SGAPPEARANCE*)aNode;
242  m_RAppearance->addNodeRef( this );
243  }
244 
245  return true;
246  }
247 
248  if( S3D::SGTYPE_FACESET == aNode->GetNodeType() )
249  {
250  if( m_FaceSet || m_RFaceSet )
251  {
252  if( aNode != m_FaceSet && aNode != m_RFaceSet )
253  {
254  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] assigning multiple FaceSet nodes",
255  __FILE__, __FUNCTION__, __LINE__ );
256 
257  return false;
258  }
259 
260  return true;
261  }
262 
263  if( isChild )
264  {
265  m_FaceSet = (SGFACESET*)aNode;
266  m_FaceSet->SetParent( this );
267  }
268  else
269  {
270  m_RFaceSet = (SGFACESET*)aNode;
271  m_RFaceSet->addNodeRef( this );
272  }
273 
274  return true;
275  }
276 
277  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] object %s is not a valid type for this object (%d)",
278  __FILE__, __FUNCTION__, __LINE__, aNode->GetName(), aNode->GetNodeType() );
279 
280  return false;
281 }
Define an indexed face set for a scenegraph.
Definition: sg_faceset.h:46
void addNodeRef(SGNODE *aNode)
Add a pointer to a node which references this node, but does not own.
Definition: sg_node.cpp:170
SGFACESET * m_RFaceSet
Definition: sg_shape.h:77
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Set the parent SGNODE of this object.
const char * GetName(void)
Definition: sg_node.cpp:146
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:72
SGFACESET * m_FaceSet
Definition: sg_shape.h:73
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Set the parent SGNODE of this object.
Definition: sg_faceset.cpp:117
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:76
Defines the generic material appearance of a scenegraph object.
Definition: sg_appearance.h:37
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104

References SGNODE::addNodeRef(), SGNODE::GetName(), SGNODE::GetNodeType(), m_Appearance, m_FaceSet, m_RAppearance, m_RFaceSet, SGAPPEARANCE::SetParent(), SGFACESET::SetParent(), S3D::SGTYPE_APPEARANCE, and S3D::SGTYPE_FACESET.

Referenced by AddChildNode(), and AddRefNode().

◆ addNodeRef()

void SGNODE::addNodeRef ( SGNODE aNode)
inherited

Add a pointer to a node which references this node, but does not own.

Such back-pointers are required to ensure that invalidated references are removed when a node is deleted.

Parameters
aNodeis the node holding a reference to this object.

Definition at line 170 of file sg_node.cpp.

171 {
172  if( nullptr == aNode )
173  return;
174 
175  std::list< SGNODE* >::iterator np =
176  std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
177 
178  if( np != m_BackPointers.end() )
179  return;
180 
181  m_BackPointers.push_back( aNode );
182 }
std::list< SGNODE * > m_BackPointers
nodes which hold a reference to this.
Definition: sg_node.h:226

References SGNODE::m_BackPointers.

Referenced by addNode(), SGFACESET::addNode(), ReadCache(), and SGFACESET::ReadCache().

◆ AddRefNode()

bool SGSHAPE::AddRefNode ( SGNODE aNode)
overridevirtual

Implements SGNODE.

Definition at line 284 of file sg_shape.cpp.

285 {
286  return addNode( aNode, false );
287 }
bool addNode(SGNODE *aNode, bool isChild)
Definition: sg_shape.cpp:215

References addNode().

◆ AssociateWrapper()

void SGNODE::AssociateWrapper ( SGNODE **  aWrapperRef)
noexceptinherited

Associate this object with a handle to itself.

The handle is typically held by an IFSG* wrapper and the pointer which it refers to is set to NULL upon destruction of this object. This mechanism provides a scheme by which a wrapper can be notified of the destruction of the object which it wraps.

Definition at line 205 of file sg_node.cpp.

206 {
207  wxCHECK( aWrapperRef && *aWrapperRef == this, /* void */ );
208 
209  // if there is an existing association then break it and emit a warning
210  // just in case the behavior is undesired
211  if( m_Association )
212  {
213  *m_Association = nullptr;
214 
215  wxLogTrace( MASK_3D_SG,
216  "%s:%s:%d * [WARNING] association being broken with previous wrapper",
217  __FILE__, __FUNCTION__, __LINE__ );
218  }
219 
220  m_Association = aWrapperRef;
221 }
SGNODE ** m_Association
Handle to the instance held by a wrapper.
Definition: sg_node.h:233

Referenced by S3D::AssociateSGNodeWrapper(), IFSG_APPEARANCE::Attach(), IFSG_COORDINDEX::Attach(), IFSG_NORMALS::Attach(), IFSG_SHAPE::Attach(), IFSG_COORDS::Attach(), IFSG_FACESET::Attach(), IFSG_COLORS::Attach(), IFSG_TRANSFORM::Attach(), IFSG_APPEARANCE::IFSG_APPEARANCE(), IFSG_COLORS::IFSG_COLORS(), IFSG_COORDINDEX::IFSG_COORDINDEX(), IFSG_COORDS::IFSG_COORDS(), IFSG_FACESET::IFSG_FACESET(), IFSG_NORMALS::IFSG_NORMALS(), IFSG_SHAPE::IFSG_SHAPE(), IFSG_TRANSFORM::IFSG_TRANSFORM(), IFSG_APPEARANCE::NewNode(), IFSG_SHAPE::NewNode(), IFSG_FACESET::NewNode(), IFSG_COORDS::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_NORMALS::NewNode(), IFSG_COLORS::NewNode(), and IFSG_TRANSFORM::NewNode().

◆ delNodeRef()

void SGNODE::delNodeRef ( const SGNODE aNode)
inherited

Remove a pointer to a node which references this node, but does not own.

Parameters
aNodeis the node holding a reference to this object.

Definition at line 185 of file sg_node.cpp.

186 {
187  if( nullptr == aNode )
188  return;
189 
190  std::list< SGNODE* >::iterator np =
191  std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
192 
193  if( np != m_BackPointers.end() )
194  {
195  m_BackPointers.erase( np );
196  return;
197  }
198 
199  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] delNodeRef() did not find its target, "
200  "this node type %d, referenced node type %d", __FILE__, __FUNCTION__, __LINE__,
201  m_SGtype, aNode->GetNodeType() );
202 }
S3D::SGTYPES m_SGtype
Type of Scene Graph node.
Definition: sg_node.h:228
std::list< SGNODE * > m_BackPointers
nodes which hold a reference to this.
Definition: sg_node.h:226
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104

References SGNODE::GetNodeType(), SGNODE::m_BackPointers, and SGNODE::m_SGtype.

Referenced by unlinkNode(), SGFACESET::unlinkNode(), SGFACESET::~SGFACESET(), and ~SGSHAPE().

◆ DisassociateWrapper()

void SGNODE::DisassociateWrapper ( SGNODE **  aWrapperRef)
noexceptinherited

Remove the association between an IFSG* wrapper object and this object.

Definition at line 223 of file sg_node.cpp.

224 {
225  if( !m_Association )
226  return;
227 
228  wxCHECK( aWrapperRef, /* void */ );
229 
230  wxCHECK( *aWrapperRef == *m_Association && aWrapperRef == m_Association, /* void */ );
231 
232  m_Association = nullptr;
233 }
SGNODE ** m_Association
Handle to the instance held by a wrapper.
Definition: sg_node.h:233

Referenced by IFSG_APPEARANCE::Attach(), IFSG_COORDINDEX::Attach(), IFSG_FACESET::Attach(), IFSG_COORDS::Attach(), IFSG_NORMALS::Attach(), IFSG_SHAPE::Attach(), IFSG_COLORS::Attach(), IFSG_TRANSFORM::Attach(), IFSG_NODE::Destroy(), IFSG_APPEARANCE::NewNode(), IFSG_COORDS::NewNode(), IFSG_SHAPE::NewNode(), IFSG_NORMALS::NewNode(), IFSG_FACESET::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_COLORS::NewNode(), IFSG_TRANSFORM::NewNode(), and IFSG_NODE::~IFSG_NODE().

◆ FindNode()

SGNODE * SGSHAPE::FindNode ( const char *  aNodeName,
const SGNODE aCaller 
)
overridevirtual

Search the tree of linked nodes and return a reference to the first node found with the given name.

The reference is then typically added to another node via AddRefNode().

Parameters
aNodeNameis the name of the node to search for.
aCalleris a pointer to the node invoking this function.
Returns
is a valid node pointer on success, otherwise NULL.

Implements SGNODE.

Definition at line 124 of file sg_shape.cpp.

125 {
126  if( nullptr == aNodeName || 0 == aNodeName[0] )
127  return nullptr;
128 
129  if( !m_Name.compare( aNodeName ) )
130  return this;
131 
132  SGNODE* tmp = nullptr;
133 
134  if( nullptr != m_Appearance )
135  {
136  tmp = m_Appearance->FindNode( aNodeName, this );
137 
138  if( tmp )
139  {
140  return tmp;
141  }
142  }
143 
144  if( nullptr != m_FaceSet )
145  {
146  tmp = m_FaceSet->FindNode( aNodeName, this );
147 
148  if( tmp )
149  {
150  return tmp;
151  }
152  }
153 
154  // query the parent if appropriate
155  if( aCaller == m_Parent || nullptr == m_Parent )
156  return nullptr;
157 
158  return m_Parent->FindNode( aNodeName, this );
159 }
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) noexcept override
Search the tree of linked nodes and return a reference to the first node found with the given name.
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) override
Search the tree of linked nodes and return a reference to the first node found with the given name.
Definition: sg_faceset.cpp:147
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:72
SGFACESET * m_FaceSet
Definition: sg_shape.h:73
virtual SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller)=0
Search the tree of linked nodes and return a reference to the first node found with the given name.
std::string m_Name
name to use for referencing the entity by name.
Definition: sg_node.h:229

References SGFACESET::FindNode(), SGAPPEARANCE::FindNode(), SGNODE::FindNode(), m_Appearance, m_FaceSet, SGNODE::m_Name, and SGNODE::m_Parent.

Referenced by ReadCache().

◆ GetName()

◆ GetNodeType()

◆ GetNodeTypeName()

const char * SGNODE::GetNodeTypeName ( S3D::SGTYPES  aNodeType) const
noexceptinherited

Definition at line 164 of file sg_node.cpp.

165 {
166  return node_names[aNodeType].c_str();
167 }
static const std::string node_names[S3D::SGTYPE_END+1]
Definition: sg_node.cpp:36

References node_names.

Referenced by IFSG_NODE::GetNodeTypeName(), IFSG_APPEARANCE::NewNode(), IFSG_COORDS::NewNode(), IFSG_NORMALS::NewNode(), IFSG_FACESET::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_COLORS::NewNode(), and IFSG_TRANSFORM::NewNode().

◆ GetParent()

SGNODE * SGNODE::GetParent ( void  ) const
noexceptinherited

Returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.

top level transform).

Definition at line 110 of file sg_node.cpp.

111 {
112  return m_Parent;
113 }
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227

Referenced by IFSG_NODE::GetParent(), S3D::GetSGNodeParent(), IFSG_APPEARANCE::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_FACESET::NewNode(), IFSG_NORMALS::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDS::NewNode(), IFSG_COLORS::NewNode(), IFSG_TRANSFORM::NewNode(), WriteCache(), SGNORMALS::WriteCache(), SCENEGRAPH::WriteCache(), SGCOLORS::WriteCache(), SGFACESET::WriteCache(), SGCOORDS::WriteCache(), SGAPPEARANCE::WriteCache(), and SGINDEX::WriteCache().

◆ isWritten()

bool SGNODE::isWritten ( void  )
inlinenoexceptinherited

Return true if the object had already been written to a cache file or VRML file.

For internal use only.

Definition at line 220 of file sg_node.h.

221  {
222  return m_written;
223  }
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230

References SGNODE::m_written.

Referenced by WriteCache(), SCENEGRAPH::WriteCache(), and SGFACESET::WriteCache().

◆ Prepare()

bool SGSHAPE::Prepare ( const glm::dmat4 *  aTransform,
S3D::MATLIST materials,
std::vector< SMESH > &  meshes 
)

Definition at line 594 of file sg_shape.cpp.

596 {
597  SMESH m;
598  S3D::INIT_SMESH( m );
599 
601  SGFACESET* pf = m_FaceSet;
602 
603  if( nullptr == pa )
604  pa = m_RAppearance;
605 
606  if( nullptr == pf )
607  pf = m_RFaceSet;
608 
609  // no face sets = nothing to render, which is valid though pointless
610  if( nullptr == pf )
611  return true;
612 
613  if( !pf->validate() )
614  {
615  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] bad model; inconsistent data",
616  __FILE__, __FUNCTION__, __LINE__ );
617 
618  return true;
619  }
620 
621  if( nullptr == pa )
622  {
623  m.m_MaterialIdx = 0;
624  }
625  else
626  {
627  int idx;
628 
629  if( !S3D::GetMatIndex( materials, pa, idx ) )
630  {
631  m.m_MaterialIdx = 0;
632  }
633  else
634  {
635  m.m_MaterialIdx = idx;
636  }
637  }
638 
639  SGCOLORS* pc = pf->m_Colors;
640  SGCOORDS* pv = pf->m_Coords;
641  SGCOORDINDEX* vidx = pf->m_CoordIndices;
642  SGNORMALS* pn = pf->m_Normals;
643 
644  if( nullptr == pc )
645  pc = pf->m_RColors;
646 
647  if( nullptr == pv )
648  pv = pf->m_RCoords;
649 
650  if( nullptr == pn )
651  pn = pf->m_RNormals;
652 
653  // set the vertex points and indices
654  size_t nCoords = 0;
655  SGPOINT* pCoords = nullptr;
656  pv->GetCoordsList( nCoords, pCoords );
657 
658  size_t nColors = 0;
659  SGCOLOR* pColors = nullptr;
660 
661  if( pc )
662  {
663  // check the vertex colors
664  pc->GetColorList( nColors, pColors );
665 
666  if( nColors < nCoords )
667  {
668  wxLogTrace( MASK_3D_SG,
669  "%s:%s:%d * [INFO] bad model; not enough colors per vertex (%ul vs %ul)",
670  __FILE__, __FUNCTION__, __LINE__, static_cast<unsigned long>( nColors ),
671  static_cast<unsigned long>( nCoords ) );
672 
673  return true;
674  }
675  }
676 
677  // set the vertex indices
678  size_t nvidx = 0;
679  int* lv = nullptr;
680  vidx->GetIndices( nvidx, lv );
681 
682  // note: reduce the vertex set to include only the referenced vertices
683  std::vector< int > vertices; // store the list of temp vertex indices
684  std::map< int, unsigned int > indexmap; // map temp vertex to true vertex
685  std::map< int, unsigned int >::iterator mit;
686 
687  for( unsigned int i = 0; i < nvidx; ++i )
688  {
689  mit = indexmap.find( lv[i] );
690 
691  if( mit == indexmap.end() )
692  {
693  indexmap.insert( std::pair< int, unsigned int >( lv[i], vertices.size() ) );
694  vertices.push_back( lv[i] );
695  }
696  }
697 
698  if( vertices.size() < 3 )
699  {
700  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] bad model; not enough vertices",
701  __FILE__, __FUNCTION__, __LINE__ );
702 
703  return true;
704  }
705 
706  // construct the final vertex/color list
707  SFVEC3F* lColors = nullptr;
708  SFVEC3F* lCoords = new SFVEC3F[ vertices.size() ];
709  int ti;
710 
711  if( pc )
712  {
713  lColors = new SFVEC3F[vertices.size()];
714  m.m_Color = lColors;
715  }
716 
717  if( pc )
718  {
719  for( size_t i = 0; i < vertices.size(); ++i )
720  {
721  ti = vertices[i];
722  glm::dvec4 pt( pCoords[ti].x, pCoords[ti].y, pCoords[ti].z, 1.0 );
723  pt = (*aTransform) * pt;
724  pColors[ti].GetColor( lColors[i].x, lColors[i].y, lColors[i].z );
725  lCoords[i] = SFVEC3F( pt.x, pt.y, pt.z );
726  }
727  }
728  else
729  {
730  for( size_t i = 0; i < vertices.size(); ++i )
731  {
732  ti = vertices[i];
733  glm::dvec4 pt( pCoords[ti].x, pCoords[ti].y, pCoords[ti].z, 1.0 );
734  pt = (*aTransform) * pt;
735  lCoords[i] = SFVEC3F( pt.x, pt.y, pt.z );
736  }
737  }
738 
739  m.m_VertexSize = (unsigned int) vertices.size();
740  m.m_Positions = lCoords;
741  unsigned int* lvidx = new unsigned int[ nvidx ];
742 
743  for( unsigned int i = 0; i < nvidx; ++i )
744  {
745  mit = indexmap.find( lv[i] );
746  lvidx[i] = mit->second;
747  }
748 
749  m.m_FaceIdxSize = (unsigned int )nvidx;
750  m.m_FaceIdx = lvidx;
751 
752  // set the per-vertex normals
753  size_t nNorms = 0;
754  SGVECTOR* pNorms = nullptr;
755  double x, y, z;
756 
757  pn->GetNormalList( nNorms, pNorms );
758  SFVEC3F* lNorms = new SFVEC3F[ vertices.size() ];
759 
760  for( size_t i = 0; i < vertices.size(); ++i )
761  {
762  ti = vertices[i];
763  pNorms[ti].GetVector( x, y, z );
764  glm::dvec4 pt( x, y, z, 0.0 );
765  pt = (*aTransform) * pt;
766 
767  lNorms[i] = SFVEC3F( pt.x, pt.y, pt.z );
768  }
769 
770  m.m_Normals = lNorms;
771  meshes.push_back( m );
772 
773  return true;
774 }
SFVEC3F * m_Normals
Vertex normals array.
Definition: c3dmodel.h:80
Define an indexed face set for a scenegraph.
Definition: sg_faceset.h:46
Define an RGB color set for a scenegraph object.
Definition: sg_colors.h:38
SGCOORDINDEX * m_CoordIndices
Definition: sg_faceset.h:81
An object to maintain a coordinate index list.
Definition: sg_coordindex.h:42
bool GetColorList(size_t &aListSize, SGCOLOR *&aColorList)
Definition: sg_colors.cpp:127
SGCOLORS * m_Colors
Definition: sg_faceset.h:79
bool GetMatIndex(MATLIST &aList, SGNODE *aNode, int &aIndex)
Definition: sg_node.cpp:243
Define a vertex coordinate set for a scenegraph object.
Definition: sg_coords.h:40
SGFACESET * m_RFaceSet
Definition: sg_shape.h:77
bool GetCoordsList(size_t &aListSize, SGPOINT *&aCoordsList)
Definition: sg_coords.cpp:129
SFVEC3F * m_Positions
Vertex position array.
Definition: c3dmodel.h:79
Per-vertex normal/color/texcoors structure.
Definition: c3dmodel.h:76
void GetColor(float &aRedVal, float &aGreenVal, float &aBlueVal) const noexcept
Definition: sg_base.cpp:59
SGCOLORS * m_RColors
Definition: sg_faceset.h:85
Define a set of vertex normals for a scene graph object.
Definition: sg_normals.h:38
unsigned int m_FaceIdxSize
Number of elements of the m_FaceIdx array.
Definition: c3dmodel.h:83
unsigned int m_VertexSize
Number of vertex in the arrays.
Definition: c3dmodel.h:78
SGCOORDS * m_RCoords
Definition: sg_faceset.h:86
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:72
bool GetIndices(size_t &nIndices, int *&aIndexList)
Retrieve the number of indices and a pointer to the list.
Definition: sg_index.cpp:124
SFVEC3F * m_Color
Vertex color array, can be NULL.
Definition: c3dmodel.h:82
void INIT_SMESH(SMESH &aMesh) noexcept
Definition: sg_node.cpp:274
SGFACESET * m_FaceSet
Definition: sg_shape.h:73
bool validate(void)
Definition: sg_faceset.cpp:831
SGCOORDS * m_Coords
Definition: sg_faceset.h:80
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
unsigned int m_MaterialIdx
Material Index to be used in this mesh (must be < m_MaterialsSize )
Definition: c3dmodel.h:85
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:76
SGNORMALS * m_Normals
Definition: sg_faceset.h:82
unsigned int * m_FaceIdx
Triangle Face Indexes.
Definition: c3dmodel.h:84
SGNORMALS * m_RNormals
Definition: sg_faceset.h:87
void GetVector(double &aXVal, double &aYVal, double &aZVal) const noexcept
Definition: sg_base.cpp:225
bool GetNormalList(size_t &aListSize, SGVECTOR *&aNormalList)
Definition: sg_normals.cpp:127
Defines the generic material appearance of a scenegraph object.
Definition: sg_appearance.h:37

References SGCOLOR::GetColor(), SGCOLORS::GetColorList(), SGCOORDS::GetCoordsList(), SGINDEX::GetIndices(), S3D::GetMatIndex(), SGNORMALS::GetNormalList(), SGVECTOR::GetVector(), S3D::INIT_SMESH(), m_Appearance, SMESH::m_Color, SGFACESET::m_Colors, SGFACESET::m_CoordIndices, SGFACESET::m_Coords, SMESH::m_FaceIdx, SMESH::m_FaceIdxSize, m_FaceSet, SMESH::m_MaterialIdx, SMESH::m_Normals, SGFACESET::m_Normals, SMESH::m_Positions, m_RAppearance, SGFACESET::m_RColors, SGFACESET::m_RCoords, m_RFaceSet, SGFACESET::m_RNormals, SMESH::m_VertexSize, and SGFACESET::validate().

◆ ReadCache()

bool SGSHAPE::ReadCache ( std::istream &  aFile,
SGNODE parentNode 
)
overridevirtual

Reads binary format data from a cache file.

To read a cache file, open the file for reading and invoke this function from a new SCENEGRAPH node.

Implements SGNODE.

Definition at line 444 of file sg_shape.cpp.

445 {
446  wxCHECK( m_Appearance == nullptr && m_RAppearance == nullptr && m_FaceSet == nullptr &&
447  m_RFaceSet == nullptr, false );
448 
449  #define NITEMS 4
450  bool items[NITEMS];
451 
452  for( int i = 0; i < NITEMS; ++i )
453  aFile.read( (char*)&items[i], sizeof(bool) );
454 
455  if( ( items[0] && items[1] ) || ( items[2] && items[3] ) )
456  {
457  wxLogTrace( MASK_3D_SG,
458  "%s:%s:%d * [INFO] corrupt data; multiple item definitions at position %ul",
459  __FILE__, __FUNCTION__, __LINE__, static_cast<unsigned long>( aFile.tellg() ) );
460 
461  return false;
462  }
463 
464  std::string name;
465 
466  if( items[0] )
467  {
468  if( S3D::SGTYPE_APPEARANCE != S3D::ReadTag( aFile, name ) )
469  {
470  wxLogTrace( MASK_3D_SG,
471  "%s:%s:%d * [INFO] corrupt data; bad child appearance tag at position %ul",
472  __FILE__, __FUNCTION__, __LINE__,
473  static_cast<unsigned long>( aFile.tellg() ) );
474 
475  return false;
476  }
477 
478  m_Appearance = new SGAPPEARANCE( this );
479  m_Appearance->SetName( name.c_str() );
480 
481  if( !m_Appearance->ReadCache( aFile, this ) )
482  {
483  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] corrupt data while reading appearance '%s'",
484  __FILE__, __FUNCTION__, __LINE__, name );
485 
486  return false;
487  }
488  }
489 
490  if( items[1] )
491  {
492  if( S3D::SGTYPE_APPEARANCE != S3D::ReadTag( aFile, name ) )
493  {
494  wxLogTrace( MASK_3D_SG,
495  "%s:%s:%d * [INFO] corrupt data; bad ref appearance tag at position %ul",
496  __FILE__, __FUNCTION__, __LINE__,
497  static_cast<unsigned long>( aFile.tellg() ) );
498 
499  return false;
500  }
501 
502  SGNODE* np = FindNode( name.c_str(), this );
503 
504  if( !np )
505  {
506  wxLogTrace( MASK_3D_SG,
507  "%s:%s:%d * [INFO] corrupt data: cannot find ref appearance '%s'",
508  __FILE__, __FUNCTION__, __LINE__, name );
509 
510  return false;
511  }
512 
513  if( S3D::SGTYPE_APPEARANCE != np->GetNodeType() )
514  {
515  wxLogTrace( MASK_3D_SG,
516  "%s:%s:%d * [INFO] corrupt data: type is not SGAPPEARANCE '%s'",
517  __FILE__, __FUNCTION__, __LINE__, name );
518 
519  return false;
520  }
521 
523  m_RAppearance->addNodeRef( this );
524  }
525 
526  if( items[2] )
527  {
528  if( S3D::SGTYPE_FACESET != S3D::ReadTag( aFile, name ) )
529  {
530  wxLogTrace( MASK_3D_SG,
531  "%s:%s:%d * [INFO] corrupt data; bad child face set tag at position %ul",
532  __FILE__, __FUNCTION__, __LINE__,
533  static_cast<unsigned long>( aFile.tellg() ) );
534 
535  return false;
536  }
537 
538  m_FaceSet = new SGFACESET( this );
539  m_FaceSet->SetName( name.c_str() );
540 
541  if( !m_FaceSet->ReadCache( aFile, this ) )
542  {
543  wxLogTrace( MASK_3D_SG,
544  "%s:%s:%d * [INFO] corrupt data while reading face set '%s'",
545  __FILE__, __FUNCTION__, __LINE__, name );
546 
547  return false;
548  }
549  }
550 
551  if( items[3] )
552  {
553  if( S3D::SGTYPE_FACESET != S3D::ReadTag( aFile, name ) )
554  {
555  wxLogTrace( MASK_3D_SG,
556  "%s:%s:%d * [INFO] corrupt data; bad ref face set tag at position %ul",
557  __FILE__, __FUNCTION__, __LINE__,
558  static_cast<unsigned long>( aFile.tellg() ) );
559 
560  return false;
561  }
562 
563  SGNODE* np = FindNode( name.c_str(), this );
564 
565  if( !np )
566  {
567  wxLogTrace( MASK_3D_SG,
568  "%s:%s:%d * [INFO] corrupt data: cannot find ref face set '%s'",
569  __FILE__, __FUNCTION__, __LINE__, name );
570 
571  return false;
572  }
573 
574  if( S3D::SGTYPE_FACESET != np->GetNodeType() )
575  {
576  wxLogTrace( MASK_3D_SG,
577  "%s:%s:%d * [INFO] corrupt data: type is not SGFACESET '%s'",
578  __FILE__, __FUNCTION__, __LINE__, name );
579 
580  return false;
581  }
582 
583  m_RFaceSet = (SGFACESET*)np;
584  m_RFaceSet->addNodeRef( this );
585  }
586 
587  if( aFile.fail() )
588  return false;
589 
590  return true;
591 }
Define an indexed face set for a scenegraph.
Definition: sg_faceset.h:46
void addNodeRef(SGNODE *aNode)
Add a pointer to a node which references this node, but does not own.
Definition: sg_node.cpp:170
bool ReadCache(std::istream &aFile, SGNODE *parentNode) override
Reads binary format data from a cache file.
SGFACESET * m_RFaceSet
Definition: sg_shape.h:77
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
bool ReadCache(std::istream &aFile, SGNODE *parentNode) override
Reads binary format data from a cache file.
Definition: sg_faceset.cpp:595
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:72
S3D::SGTYPES ReadTag(std::istream &aFile, std::string &aName)
Read the text tag of a binary cache file which is the NodeTag and unique ID number combined.
Definition: sg_helpers.cpp:195
#define NITEMS
SGFACESET * m_FaceSet
Definition: sg_shape.h:73
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) override
Search the tree of linked nodes and return a reference to the first node found with the given name.
Definition: sg_shape.cpp:124
void SetName(const char *aName)
Definition: sg_node.cpp:155
const char * name
Definition: DXF_plotter.cpp:59
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:76
Defines the generic material appearance of a scenegraph object.
Definition: sg_appearance.h:37
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104

References SGNODE::addNodeRef(), FindNode(), SGNODE::GetNodeType(), m_Appearance, m_FaceSet, m_RAppearance, m_RFaceSet, name, NITEMS, SGFACESET::ReadCache(), SGAPPEARANCE::ReadCache(), S3D::ReadTag(), SGNODE::SetName(), S3D::SGTYPE_APPEARANCE, and S3D::SGTYPE_FACESET.

Referenced by SCENEGRAPH::ReadCache().

◆ ReNameNodes()

void SGSHAPE::ReNameNodes ( void  )
overridevirtual

Rename a node and all its child nodes in preparation for write operations.

Implements SGNODE.

Definition at line 296 of file sg_shape.cpp.

297 {
298  m_written = false;
299 
300  // rename this node
301  m_Name.clear();
302  GetName();
303 
304  // rename Appearance
305  if( m_Appearance )
307 
308  // rename FaceSet
309  if( m_FaceSet )
311 }
void ReNameNodes(void) override
Rename a node and all its child nodes in preparation for write operations.
void ReNameNodes(void) override
Rename a node and all its child nodes in preparation for write operations.
Definition: sg_faceset.cpp:408
const char * GetName(void)
Definition: sg_node.cpp:146
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:72
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230
SGFACESET * m_FaceSet
Definition: sg_shape.h:73
std::string m_Name
name to use for referencing the entity by name.
Definition: sg_node.h:229

References SGNODE::GetName(), m_Appearance, m_FaceSet, SGNODE::m_Name, SGNODE::m_written, SGFACESET::ReNameNodes(), and SGAPPEARANCE::ReNameNodes().

◆ ResetNodeIndex()

void SGNODE::ResetNodeIndex ( void  )
noexceptinherited

Reset the global SG* node indices in preparation for write operations.

Definition at line 236 of file sg_node.cpp.

237 {
238  for( int i = 0; i < (int)S3D::SGTYPE_END; ++i )
239  node_counts[i] = 1;
240 }
static unsigned int node_counts[S3D::SGTYPE_END]
Definition: sg_node.cpp:50

References node_counts, and S3D::SGTYPE_END.

Referenced by S3D::ResetNodeIndex(), SCENEGRAPH::WriteCache(), and S3D::WriteVRML().

◆ SetName()

void SGNODE::SetName ( const char *  aName)
inherited

Definition at line 155 of file sg_node.cpp.

156 {
157  if( nullptr == aName || 0 == aName[0] )
159  else
160  m_Name = aName;
161 }
std::string m_Name
name to use for referencing the entity by name.
Definition: sg_node.h:229
S3D::SGTYPES m_SGtype
Type of Scene Graph node.
Definition: sg_node.h:228
static void getNodeName(S3D::SGTYPES nodeType, std::string &aName)
Definition: sg_node.cpp:59

References getNodeName(), SGNODE::m_Name, and SGNODE::m_SGtype.

Referenced by ReadCache(), SCENEGRAPH::ReadCache(), SGFACESET::ReadCache(), and IFSG_NODE::SetName().

◆ SetParent()

bool SGSHAPE::SetParent ( SGNODE aParent,
bool  notify = true 
)
overridevirtual

Set the parent SGNODE of this object.

Parameters
aParent[in] is the desired parent node
Returns
true if the operation succeeds; false if the given node is not allowed to be a parent to the derived object.

Implements SGNODE.

Definition at line 94 of file sg_shape.cpp.

95 {
96  if( nullptr != m_Parent )
97  {
98  if( aParent == m_Parent )
99  return true;
100 
101  // handle the change in parents
102  if( notify )
103  m_Parent->unlinkChildNode( this );
104 
105  m_Parent = nullptr;
106 
107  if( nullptr == aParent )
108  return true;
109  }
110 
111  // only a SGTRANSFORM may be parent to a SGSHAPE
112  if( nullptr != aParent && S3D::SGTYPE_TRANSFORM != aParent->GetNodeType() )
113  return false;
114 
115  m_Parent = aParent;
116 
117  if( m_Parent )
118  m_Parent->AddChildNode( this );
119 
120  return true;
121 }
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
virtual void unlinkChildNode(const SGNODE *aNode)=0
Remove references to an owned child.
virtual bool AddChildNode(SGNODE *aNode)=0
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104

References SGNODE::AddChildNode(), SGNODE::GetNodeType(), SGNODE::m_Parent, S3D::SGTYPE_TRANSFORM, and SGNODE::unlinkChildNode().

◆ SwapParent()

bool SGNODE::SwapParent ( SGNODE aNewParent)
inherited

Swap the ownership with the given parent.

This operation may be required when reordering nodes for optimization.

Parameters
aNewParentwill become the new parent to the object; it must be the same type as the parent of this instance.

Definition at line 116 of file sg_node.cpp.

117 {
118  if( aNewParent == m_Parent )
119  return true;
120 
121  if( nullptr == aNewParent )
122  return false;
123 
124  if( nullptr == m_Parent )
125  {
126  if( aNewParent->AddChildNode( this ) )
127  return true;
128 
129  return false;
130  }
131 
132  if( aNewParent->GetNodeType() != m_Parent->GetNodeType() )
133  return false;
134 
135  SGNODE* oldParent = m_Parent;
136  m_Parent->unlinkChildNode( this );
137  m_Parent = nullptr;
138  aNewParent->unlinkRefNode( this );
139  aNewParent->AddChildNode( this );
140  oldParent->AddRefNode( this );
141 
142  return true;
143 }
virtual bool AddRefNode(SGNODE *aNode)=0
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
virtual void unlinkRefNode(const SGNODE *aNode)=0
Remove pointers to a referenced node.
virtual void unlinkChildNode(const SGNODE *aNode)=0
Remove references to an owned child.
virtual bool AddChildNode(SGNODE *aNode)=0
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104

References SGNODE::AddChildNode(), SGNODE::AddRefNode(), SGNODE::GetNodeType(), SGNODE::m_Parent, SGNODE::unlinkChildNode(), and SGNODE::unlinkRefNode().

Referenced by WriteCache(), and SGFACESET::WriteCache().

◆ unlinkChildNode()

void SGSHAPE::unlinkChildNode ( const SGNODE aNode)
overridevirtual

Remove references to an owned child.

This is invoked by the child upon destruction to ensure that the parent has no invalid references.

Parameters
aNodeis the child which is being deleted.

Implements SGNODE.

Definition at line 203 of file sg_shape.cpp.

204 {
205  unlinkNode( aNode, true );
206 }
void unlinkNode(const SGNODE *aNode, bool isChild)
Definition: sg_shape.cpp:162

References unlinkNode().

◆ unlinkNode()

void SGSHAPE::unlinkNode ( const SGNODE aNode,
bool  isChild 
)
private

Definition at line 162 of file sg_shape.cpp.

163 {
164  if( nullptr == aNode )
165  return;
166 
167  if( isChild )
168  {
169  if( aNode == m_Appearance )
170  {
171  m_Appearance = nullptr;
172  return;
173  }
174 
175  if( aNode == m_FaceSet )
176  {
177  m_FaceSet = nullptr;
178  return;
179  }
180  }
181  else
182  {
183  if( aNode == m_RAppearance )
184  {
185  delNodeRef( this );
186  m_RAppearance = nullptr;
187  return;
188  }
189 
190  if( aNode == m_RFaceSet )
191  {
192  delNodeRef( this );
193  m_RFaceSet = nullptr;
194  return;
195  }
196  }
197 
198  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] unlinkNode() did not find its target",
199  __FILE__, __FUNCTION__, __LINE__ );
200 }
SGFACESET * m_RFaceSet
Definition: sg_shape.h:77
void delNodeRef(const SGNODE *aNode)
Remove a pointer to a node which references this node, but does not own.
Definition: sg_node.cpp:185
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:72
SGFACESET * m_FaceSet
Definition: sg_shape.h:73
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:76

References SGNODE::delNodeRef(), m_Appearance, m_FaceSet, m_RAppearance, and m_RFaceSet.

Referenced by unlinkChildNode(), and unlinkRefNode().

◆ unlinkRefNode()

void SGSHAPE::unlinkRefNode ( const SGNODE aNode)
overridevirtual

Remove pointers to a referenced node.

This is invoked by the referenced node upon destruction to ensure that the referring node has no invalid references.

Parameters
aNodeis the node which is being deleted.

Implements SGNODE.

Definition at line 209 of file sg_shape.cpp.

210 {
211  unlinkNode( aNode, false );
212 }
void unlinkNode(const SGNODE *aNode, bool isChild)
Definition: sg_shape.cpp:162

References unlinkNode().

◆ WriteCache()

bool SGSHAPE::WriteCache ( std::ostream &  aFile,
SGNODE parentNode 
)
overridevirtual

Write this node's data to a binary cache file.

The data includes all data of children and references to children. If this function is invoked by the user, parentNode must be set to NULL in order to ensure coherent data.

Implements SGNODE.

Definition at line 357 of file sg_shape.cpp.

358 {
359  if( nullptr == parentNode )
360  {
361  wxCHECK( m_Parent, false );
362 
363  SGNODE* np = m_Parent;
364 
365  while( nullptr != np->GetParent() )
366  np = np->GetParent();
367 
368  if( np->WriteCache( aFile, nullptr ) )
369  {
370  m_written = true;
371  return true;
372  }
373 
374  return false;
375  }
376 
377  wxCHECK( parentNode == m_Parent, false );
378 
379  if( !aFile.good() )
380  {
381  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] bad stream", __FILE__, __FUNCTION__, __LINE__ );
382 
383  return false;
384  }
385 
386  // check if any references are unwritten and swap parents if so
387  if( nullptr != m_RAppearance && !m_RAppearance->isWritten() )
388  m_RAppearance->SwapParent(this);
389 
390  if( nullptr != m_RFaceSet && !m_RFaceSet->isWritten() )
391  m_RFaceSet->SwapParent( this );
392 
393  aFile << "[" << GetName() << "]";
394  #define NITEMS 4
395  bool items[NITEMS];
396  int i;
397 
398  for( i = 0; i < NITEMS; ++i )
399  items[i] = 0;
400 
401  i = 0;
402 
403  if( nullptr != m_Appearance )
404  items[i] = true;
405 
406  ++i;
407 
408  if( nullptr != m_RAppearance )
409  items[i] = true;
410 
411  ++i;
412 
413  if( nullptr != m_FaceSet )
414  items[i] = true;
415 
416  ++i;
417 
418  if( nullptr != m_RFaceSet )
419  items[i] = true;
420 
421  for( int jj = 0; jj < NITEMS; ++jj )
422  aFile.write( (char*)&items[jj], sizeof(bool) );
423 
424  if( items[0] )
425  m_Appearance->WriteCache( aFile, this );
426 
427  if( items[1] )
428  aFile << "[" << m_RAppearance->GetName() << "]";
429 
430  if( items[2] )
431  m_FaceSet->WriteCache( aFile, this );
432 
433  if( items[3] )
434  aFile << "[" << m_RFaceSet->GetName() << "]";
435 
436  if( aFile.fail() )
437  return false;
438 
439  m_written = true;
440  return true;
441 }
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
SGFACESET * m_RFaceSet
Definition: sg_shape.h:77
bool WriteCache(std::ostream &aFile, SGNODE *parentNode) override
Write this node's data to a binary cache file.
Definition: sg_faceset.cpp:488
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
const char * GetName(void)
Definition: sg_node.cpp:146
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:72
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230
#define NITEMS
bool SwapParent(SGNODE *aNewParent)
Swap the ownership with the given parent.
Definition: sg_node.cpp:116
SGFACESET * m_FaceSet
Definition: sg_shape.h:73
SGNODE * GetParent(void) const noexcept
Returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.
Definition: sg_node.cpp:110
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Write this node's data to a binary cache file.
bool isWritten(void) noexcept
Return true if the object had already been written to a cache file or VRML file.
Definition: sg_node.h:220
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:76
bool WriteCache(std::ostream &aFile, SGNODE *parentNode) override
Write this node's data to a binary cache file.

References SGNODE::GetName(), SGNODE::GetParent(), SGNODE::isWritten(), m_Appearance, m_FaceSet, SGNODE::m_Parent, m_RAppearance, m_RFaceSet, SGNODE::m_written, NITEMS, SGNODE::SwapParent(), SGFACESET::WriteCache(), SGAPPEARANCE::WriteCache(), and SGNODE::WriteCache().

◆ WriteVRML()

bool SGSHAPE::WriteVRML ( std::ostream &  aFile,
bool  aReuseFlag 
)
overridevirtual

Writes this node's data to a VRML file.

This includes all data of child and referenced nodes.

Implements SGNODE.

Definition at line 314 of file sg_shape.cpp.

315 {
317  {
318  return false;
319  }
320 
321  if( aReuseFlag )
322  {
323  if( !m_written )
324  {
325  aFile << "DEF " << GetName() << " Shape {\n";
326  m_written = true;
327  }
328  else
329  {
330  aFile << " USE " << GetName() << "\n";
331  return true;
332  }
333  }
334  else
335  {
336  aFile << " Shape {\n";
337  }
338 
339  if( m_Appearance )
340  m_Appearance->WriteVRML( aFile, aReuseFlag );
341 
342  if( m_RAppearance )
343  m_RAppearance->WriteVRML( aFile, aReuseFlag );
344 
345  if( m_FaceSet )
346  m_FaceSet->WriteVRML( aFile, aReuseFlag );
347 
348  if( m_RFaceSet )
349  m_RFaceSet->WriteVRML( aFile, aReuseFlag );
350 
351  aFile << "}\n";
352 
353  return true;
354 }
SGFACESET * m_RFaceSet
Definition: sg_shape.h:77
const char * GetName(void)
Definition: sg_node.cpp:146
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:72
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230
SGFACESET * m_FaceSet
Definition: sg_shape.h:73
bool WriteVRML(std::ostream &aFile, bool aReuseFlag) override
Writes this node's data to a VRML file.
bool WriteVRML(std::ostream &aFile, bool aReuseFlag) override
Writes this node's data to a VRML file.
Definition: sg_faceset.cpp:433
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:76

References SGNODE::GetName(), m_Appearance, m_FaceSet, m_RAppearance, m_RFaceSet, SGNODE::m_written, SGFACESET::WriteVRML(), and SGAPPEARANCE::WriteVRML().

Member Data Documentation

◆ m_Appearance

SGAPPEARANCE* SGSHAPE::m_Appearance

◆ m_BackPointers

std::list< SGNODE* > SGNODE::m_BackPointers
protectedinherited

nodes which hold a reference to this.

Definition at line 226 of file sg_node.h.

Referenced by SGNODE::addNodeRef(), SGCOORDS::CalcNormals(), SGNODE::delNodeRef(), and SGNODE::~SGNODE().

◆ m_FaceSet

SGFACESET* SGSHAPE::m_FaceSet

◆ m_Name

◆ m_Parent

◆ m_RAppearance

SGAPPEARANCE* SGSHAPE::m_RAppearance

Definition at line 76 of file sg_shape.h.

Referenced by addNode(), Prepare(), ReadCache(), SGSHAPE(), unlinkNode(), WriteCache(), WriteVRML(), and ~SGSHAPE().

◆ m_RFaceSet

SGFACESET* SGSHAPE::m_RFaceSet

Definition at line 77 of file sg_shape.h.

Referenced by addNode(), Prepare(), ReadCache(), SGSHAPE(), unlinkNode(), WriteCache(), WriteVRML(), and ~SGSHAPE().

◆ m_SGtype

◆ m_written


The documentation for this class was generated from the following files: