KiCad PCB EDA Suite
SGSHAPE Class Reference

#include <sg_shape.h>

Inheritance diagram for SGSHAPE:
SGNODE

Public Member Functions

void unlinkChildNode (const SGNODE *aNode) override
 Function unlinkChild removes references to an owned child; it is invoked by the child upon destruction to ensure that the parent has no invalid references. More...
 
void unlinkRefNode (const SGNODE *aNode) override
 Function unlinkRef removes pointers to a referenced node; it is invoked by the referenced node upon destruction to ensure that the referring node has no invalid references. More...
 
 SGSHAPE (SGNODE *aParent)
 
virtual ~SGSHAPE ()
 
virtual bool SetParent (SGNODE *aParent, bool notify=true) override
 Function SetParent sets the parent SGNODE of this object. More...
 
SGNODEFindNode (const char *aNodeName, const SGNODE *aCaller) override
 Function FindNode searches the tree of linked nodes and returns 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
 Function ReNameNodes renames a node and all its child nodes in preparation for Write() operations. More...
 
bool WriteVRML (std::ostream &aFile, bool aReuseFlag) override
 Function WriteVRML writes this node's data to a VRML file; this includes all data of child and referenced nodes. More...
 
bool WriteCache (std::ostream &aFile, SGNODE *parentNode) override
 Function WriteCache write's this node's data to a binary cache file; the data includes all data of children and references to children. More...
 
bool ReadCache (std::istream &aFile, SGNODE *parentNode) override
 Function ReadCache Reads binary format data from a cache file. More...
 
bool Prepare (const glm::dmat4 *aTransform, S3D::MATLIST &materials, std::vector< SMESH > &meshes)
 
void addNodeRef (SGNODE *aNode)
 Function addNodeRef adds a pointer to a node which references, but does not own, this node. More...
 
void delNodeRef (const SGNODE *aNode)
 Function delNodeRef removes a pointer to a node which references, but does not own, this node. More...
 
bool isWritten (void)
 Function IsWritten returns true if the object had already been written to a cache file or VRML file; for internal use only. More...
 
S3D::SGTYPES GetNodeType (void) const
 Function GetNodeType returns the type of this node instance. More...
 
SGNODEGetParent (void) const
 Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie. More...
 
bool SwapParent (SGNODE *aNewParent)
 Function SwapParent swaps the ownership with the given parent. More...
 
const char * GetName (void)
 
void SetName (const char *aName)
 
const char * GetNodeTypeName (S3D::SGTYPES aNodeType) const
 
void AssociateWrapper (SGNODE **aWrapperRef)
 Function AssociateWrapper associates this object with a handle to itself; this handle is typically held by an IFSG* wrapper and the pointer which it refers to is set to NULL upon destruction of this object. More...
 
void DisassociateWrapper (SGNODE **aWrapperRef)
 Function DisassociateWrapper removes the association between an IFSG* wrapper object and this object. More...
 
void ResetNodeIndex (void)
 Function ResetNodeIndex resets the global SG* node indices in preparation for Write() operations. More...
 

Public Attributes

SGAPPEARANCEm_Appearance
 
SGFACESETm_FaceSet
 
SGAPPEARANCEm_RAppearance
 
SGFACESETm_RFaceSet
 

Protected Attributes

std::list< SGNODE * > m_BackPointers
 
SGNODEm_Parent
 
S3D::SGTYPES m_SGtype
 
std::string m_Name
 
bool m_written
 

Private Member Functions

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

Detailed Description

Definition at line 39 of file sg_shape.h.

Constructor & Destructor Documentation

SGSHAPE::SGSHAPE ( SGNODE aParent)

Definition at line 39 of file sg_shape.cpp.

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.

39  : SGNODE( aParent )
40 {
42  m_Appearance = NULL;
43  m_RAppearance = NULL;
44  m_FaceSet = NULL;
45  m_RFaceSet = NULL;
46 
47  if( NULL != aParent && S3D::SGTYPE_TRANSFORM != aParent->GetNodeType() )
48  {
49  m_Parent = NULL;
50 
51 #ifdef DEBUG
52  std::ostringstream ostr;
53  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
54  ostr << " * [BUG] inappropriate parent to SGSHAPE (type ";
55  ostr << aParent->GetNodeType() << ")";
56  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
57 #endif
58  }
59  else if( NULL != aParent && S3D::SGTYPE_TRANSFORM == aParent->GetNodeType() )
60  {
61  m_Parent->AddChildNode( this );
62  }
63 
64  return;
65 }
SGNODE * m_Parent
Definition: sg_node.h:83
SGFACESET * m_RFaceSet
Definition: sg_shape.h:52
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:47
SGFACESET * m_FaceSet
Definition: sg_shape.h:48
SGNODE(SGNODE *aParent)
Definition: sg_node.cpp:76
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
virtual bool AddChildNode(SGNODE *aNode)=0
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:51
SGSHAPE::~SGSHAPE ( )
virtual

Definition at line 68 of file sg_shape.cpp.

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

69 {
70  // drop references
71  if( m_RAppearance )
72  {
73  m_RAppearance->delNodeRef( this );
74  m_RAppearance = NULL;
75  }
76 
77  if( m_RFaceSet )
78  {
79  m_RFaceSet->delNodeRef( this );
80  m_RFaceSet = NULL;
81  }
82 
83  // delete objects
84  if( m_Appearance )
85  {
86  m_Appearance->SetParent( NULL, false );
87  delete m_Appearance;
88  m_Appearance = NULL;
89  }
90 
91  if( m_FaceSet )
92  {
93  m_FaceSet->SetParent( NULL, false );
94  delete m_FaceSet;
95  m_FaceSet = NULL;
96  }
97 
98  return;
99 }
SGFACESET * m_RFaceSet
Definition: sg_shape.h:52
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Function SetParent sets the parent SGNODE of this object.
void delNodeRef(const SGNODE *aNode)
Function delNodeRef removes a pointer to a node which references, but does not own, this node.
Definition: sg_node.cpp:192
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:47
SGFACESET * m_FaceSet
Definition: sg_shape.h:48
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Function SetParent sets the parent SGNODE of this object.
Definition: sg_faceset.cpp:124
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:51

Member Function Documentation

bool SGSHAPE::AddChildNode ( SGNODE aNode)
overridevirtual

Implements SGNODE.

Definition at line 333 of file sg_shape.cpp.

References addNode().

334 {
335  return addNode( aNode, true );
336 }
bool addNode(SGNODE *aNode, bool isChild)
Definition: sg_shape.cpp:233
bool SGSHAPE::addNode ( SGNODE aNode,
bool  isChild 
)
private

Definition at line 233 of file sg_shape.cpp.

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().

234 {
235  if( NULL == aNode )
236  {
237  #ifdef DEBUG
238  std::ostringstream ostr;
239  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
240  ostr << " * [BUG] NULL pointer passed for aNode";
241  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
242  #endif
243 
244  return false;
245  }
246 
247  if( S3D::SGTYPE_APPEARANCE == aNode->GetNodeType() )
248  {
249  if( m_Appearance || m_RAppearance )
250  {
251  if( aNode != m_Appearance && aNode != m_RAppearance )
252  {
253  #ifdef DEBUG
254  std::ostringstream ostr;
255  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
256  ostr << " * [BUG] assigning multiple Appearance nodes";
257  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
258  #endif
259 
260  return false;
261  }
262 
263  return true;
264  }
265 
266  if( isChild )
267  {
268  m_Appearance = (SGAPPEARANCE*)aNode;
269  m_Appearance->SetParent( this );
270  }
271  else
272  {
273  m_RAppearance = (SGAPPEARANCE*)aNode;
274  m_RAppearance->addNodeRef( this );
275  }
276 
277  return true;
278  }
279 
280  if( S3D::SGTYPE_FACESET == aNode->GetNodeType() )
281  {
282  if( m_FaceSet || m_RFaceSet )
283  {
284  if( aNode != m_FaceSet && aNode != m_RFaceSet )
285  {
286  #ifdef DEBUG
287  std::ostringstream ostr;
288  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
289  ostr << " * [BUG] assigning multiple FaceSet nodes";
290  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
291  #endif
292 
293  return false;
294  }
295 
296  return true;
297  }
298 
299  if( isChild )
300  {
301  m_FaceSet = (SGFACESET*)aNode;
302  m_FaceSet->SetParent( this );
303  }
304  else
305  {
306  m_RFaceSet = (SGFACESET*)aNode;
307  m_RFaceSet->addNodeRef( this );
308  }
309 
310  return true;
311  }
312 
313  #ifdef DEBUG
314  do {
315  std::ostringstream ostr;
316  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
317  ostr << " * [BUG] object '" << aNode->GetName();
318  ostr << "' is not a valid type for this object (" << aNode->GetNodeType() << ")";
319  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
320  } while( 0 );
321  #endif
322 
323  return false;
324 }
void addNodeRef(SGNODE *aNode)
Function addNodeRef adds a pointer to a node which references, but does not own, this node...
Definition: sg_node.cpp:176
SGFACESET * m_RFaceSet
Definition: sg_shape.h:52
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Function SetParent sets the parent SGNODE of this object.
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
const char * GetName(void)
Definition: sg_node.cpp:150
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:47
SGFACESET * m_FaceSet
Definition: sg_shape.h:48
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Function SetParent sets the parent SGNODE of this object.
Definition: sg_faceset.cpp:124
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:51
void SGNODE::addNodeRef ( SGNODE aNode)
inherited

Function addNodeRef adds a pointer to a node which references, but does not own, this node.

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 176 of file sg_node.cpp.

References SGNODE::m_BackPointers.

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

177 {
178  if( NULL == aNode )
179  return;
180 
181  std::list< SGNODE* >::iterator np =
182  std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
183 
184  if( np != m_BackPointers.end() )
185  return;
186 
187  m_BackPointers.push_back( aNode );
188  return;
189 }
std::list< SGNODE * > m_BackPointers
Definition: sg_node.h:82
bool SGSHAPE::AddRefNode ( SGNODE aNode)
overridevirtual

Implements SGNODE.

Definition at line 327 of file sg_shape.cpp.

References addNode().

328 {
329  return addNode( aNode, false );
330 }
bool addNode(SGNODE *aNode, bool isChild)
Definition: sg_shape.cpp:233
void SGNODE::AssociateWrapper ( SGNODE **  aWrapperRef)
inherited

Function AssociateWrapper associates this object with a handle to itself; this 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 219 of file sg_node.cpp.

References SGNODE::m_Association.

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().

220 {
221  if( NULL == aWrapperRef )
222  {
223  #ifdef DEBUG
224  std::ostringstream ostr;
225  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
226  ostr << " * [BUG] NULL handle";
227  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
228  #endif
229 
230  return;
231  }
232 
233  if( *aWrapperRef != this )
234  {
235  #ifdef DEBUG
236  std::ostringstream ostr;
237  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
238  ostr << " * [BUG] handle value does not match this object's pointer";
239  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
240  #endif
241 
242  return;
243  }
244 
245  // if there is an existing association then break it and emit a warning
246  // just in case the behavior is undesired
247  if( m_Association )
248  {
249  *m_Association = NULL;
250 
251  #ifdef DEBUG
252  std::ostringstream ostr;
253  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
254  ostr << " * [WARNING] association being broken with previous wrapper";
255  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
256  #endif
257  }
258 
259  m_Association = aWrapperRef;
260 
261  return;
262 }
SGNODE ** m_Association
Definition: sg_node.h:79
void SGNODE::delNodeRef ( const SGNODE aNode)
inherited

Function delNodeRef removes a pointer to a node which references, but does not own, this node.

Parameters
aNodeis the node holding a reference to this object

Definition at line 192 of file sg_node.cpp.

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

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

193 {
194  if( NULL == aNode )
195  return;
196 
197  std::list< SGNODE* >::iterator np =
198  std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
199 
200  if( np != m_BackPointers.end() )
201  {
202  m_BackPointers.erase( np );
203  return;
204  }
205 
206  #ifdef DEBUG
207  std::ostringstream ostr;
208  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
209  ostr << " * [BUG] delNodeRef() did not find its target\n";
210  ostr << " * This Node Type: " << m_SGtype << ", Referenced node type: ";
211  ostr << aNode->GetNodeType() << "\n";
212  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
213  #endif
214 
215  return;
216 }
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
std::list< SGNODE * > m_BackPointers
Definition: sg_node.h:82
void SGNODE::DisassociateWrapper ( SGNODE **  aWrapperRef)
inherited

Function DisassociateWrapper removes the association between an IFSG* wrapper object and this object.

Definition at line 264 of file sg_node.cpp.

References SGNODE::GetName(), SGNODE::m_Association, SGNODE::m_SGtype, and node_names.

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().

265 {
266  if( !m_Association )
267  return;
268 
269  if( !aWrapperRef )
270  {
271  #ifdef DEBUG
272  std::ostringstream ostr;
273  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
274  ostr << " * [BUG] invalid handle value aWrapperRef";
275  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
276  #endif
277 
278  return;
279  }
280 
281  if( *aWrapperRef != *m_Association || aWrapperRef != m_Association )
282  {
283  #ifdef DEBUG
284  std::ostringstream ostr;
285  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
286  ostr << " * [BUG] *aWrapperRef (" << *aWrapperRef;
287  ostr << ") does not match *m_Association (" << *m_Association << ") in type ";
288  ostr << node_names[ m_SGtype] << "\n";
289  ostr << " * [INFO] OR aWrapperRef(" << aWrapperRef << ") != m_Association(";
290  ostr << m_Association << ")\n";
291  ostr << " * [INFO] node name: " << GetName();
292  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
293  #endif
294 
295  return;
296  }
297 
298  m_Association = NULL;
299 
300  return;
301 }
SGNODE ** m_Association
Definition: sg_node.h:79
const char * GetName(void)
Definition: sg_node.cpp:150
static const std::string node_names[S3D::SGTYPE_END+1]
Definition: sg_node.cpp:34
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
SGNODE * SGSHAPE::FindNode ( const char *  aNodeName,
const SGNODE aCaller 
)
overridevirtual

Function FindNode searches the tree of linked nodes and returns 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 132 of file sg_shape.cpp.

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

Referenced by ReadCache().

133 {
134  if( NULL == aNodeName || 0 == aNodeName[0] )
135  return NULL;
136 
137  if( !m_Name.compare( aNodeName ) )
138  return this;
139 
140  SGNODE* tmp = NULL;
141 
142  if( NULL != m_Appearance )
143  {
144  tmp = m_Appearance->FindNode( aNodeName, this );
145 
146  if( tmp )
147  {
148  return tmp;
149  }
150  }
151 
152  if( NULL != m_FaceSet )
153  {
154  tmp = m_FaceSet->FindNode( aNodeName, this );
155 
156  if( tmp )
157  {
158  return tmp;
159  }
160  }
161 
162  // query the parent if appropriate
163  if( aCaller == m_Parent || NULL == m_Parent )
164  return NULL;
165 
166  return m_Parent->FindNode( aNodeName, this );
167 }
SGNODE * m_Parent
Definition: sg_node.h:83
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) override
Function FindNode searches the tree of linked nodes and returns a reference to the first node found w...
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) override
Function FindNode searches the tree of linked nodes and returns a reference to the first node found w...
Definition: sg_faceset.cpp:154
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:47
SGFACESET * m_FaceSet
Definition: sg_shape.h:48
virtual SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller)=0
Function FindNode searches the tree of linked nodes and returns a reference to the first node found w...
std::string m_Name
Definition: sg_node.h:85
const char * SGNODE::GetNodeTypeName ( S3D::SGTYPES  aNodeType) const
inherited

Definition at line 170 of file sg_node.cpp.

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().

171 {
172  return node_names[aNodeType].c_str();
173 }
static const std::string node_names[S3D::SGTYPE_END+1]
Definition: sg_node.cpp:34
SGNODE * SGNODE::GetParent ( void  ) const
inherited
bool SGNODE::isWritten ( void  )
inlineinherited

Function IsWritten returns true if the object had already been written to a cache file or VRML file; for internal use only.

Definition at line 130 of file sg_node.h.

References SGNODE::m_written.

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

131  {
132  return m_written;
133  }
bool m_written
Definition: sg_node.h:86
bool SGSHAPE::Prepare ( const glm::dmat4 *  aTransform,
S3D::MATLIST materials,
std::vector< SMESH > &  meshes 
)

Definition at line 711 of file sg_shape.cpp.

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, SGFACESET::m_Normals, SMESH::m_Normals, SMESH::m_Positions, m_RAppearance, SGFACESET::m_RColors, SGFACESET::m_RCoords, m_RFaceSet, SGFACESET::m_RNormals, SMESH::m_VertexSize, and SGFACESET::validate().

713 {
714  SMESH m;
715  S3D::INIT_SMESH( m );
716 
718  SGFACESET* pf = m_FaceSet;
719 
720  if( NULL == pa )
721  pa = m_RAppearance;
722 
723  if( NULL == pf )
724  pf = m_RFaceSet;
725 
726  // no face sets = nothing to render, which is valid though pointless
727  if( NULL == pf )
728  return true;
729 
730  if( !pf->validate() )
731  {
732 #ifdef DEBUG
733  std::ostringstream ostr;
734  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
735  ostr << " * [INFO] bad model; inconsistent data";
736  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
737 #endif
738  return true;
739  }
740 
741  if( NULL == pa )
742  {
743  m.m_MaterialIdx = 0;
744  }
745  else
746  {
747  int idx;
748 
749  if( !S3D::GetMatIndex( materials, pa, idx ) )
750  {
751  m.m_MaterialIdx = 0;
752  }
753  else
754  {
755  m.m_MaterialIdx = idx;
756  }
757  }
758 
759  SGCOLORS* pc = pf->m_Colors;
760  SGCOORDS* pv = pf->m_Coords;
761  SGCOORDINDEX* vidx = pf->m_CoordIndices;
762  SGNORMALS* pn = pf->m_Normals;
763 
764  if( NULL == pc )
765  pc = pf->m_RColors;
766 
767  if( NULL == pv )
768  pv = pf->m_RCoords;
769 
770  if( NULL == pn )
771  pn = pf->m_RNormals;
772 
773  // set the vertex points and indices
774  size_t nCoords = 0;
775  SGPOINT* pCoords = NULL;
776  pv->GetCoordsList( nCoords, pCoords );
777 
778  size_t nColors = 0;
779  SGCOLOR* pColors = NULL;
780 
781  if( pc )
782  {
783  // check the vertex colors
784  pc->GetColorList( nColors, pColors );
785 
786  if( nColors < nCoords )
787  {
788  #ifdef DEBUG
789  std::ostringstream ostr;
790  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
791  ostr << " * [INFO] bad model; not enough colors per vertex (";
792  ostr << nColors << " vs " << nCoords << ")";
793  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
794  #endif
795  return true;
796  }
797  }
798 
799  // set the vertex indices
800  size_t nvidx = 0;
801  int* lv = NULL;
802  vidx->GetIndices( nvidx, lv );
803 
804  // note: reduce the vertex set to include only the referenced vertices
805  std::vector< int > vertices; // store the list of temp vertex indices
806  std::map< int, unsigned int > indexmap; // map temp vertex to true vertex
807  std::map< int, unsigned int >::iterator mit;
808 
809  for( unsigned int i = 0; i < nvidx; ++i )
810  {
811  mit = indexmap.find( lv[i] );
812 
813  if( mit == indexmap.end() )
814  {
815  indexmap.insert( std::pair< int, unsigned int >( lv[i], vertices.size() ) );
816  vertices.push_back( lv[i] );
817  }
818  }
819 
820  if( vertices.size() < 3 )
821  {
822  #ifdef DEBUG
823  std::ostringstream ostr;
824  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
825  ostr << " * [INFO] bad model; not enough vertices";
826  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
827  #endif
828  return true;
829  }
830 
831  // construct the final vertex/color list
832  SFVEC3F* lColors = NULL;
833  SFVEC3F* lCoords = new SFVEC3F[ vertices.size() ];
834  int ti;
835 
836  if( pc )
837  {
838  lColors = new SFVEC3F[vertices.size()];
839  m.m_Color = lColors;
840  }
841 
842 
843  if( pc )
844  {
845  for( size_t i = 0; i < vertices.size(); ++i )
846  {
847  ti = vertices[i];
848  glm::dvec4 pt( pCoords[ti].x, pCoords[ti].y, pCoords[ti].z, 1.0 );
849  pt = (*aTransform) * pt;
850  pColors[ti].GetColor( lColors[i].x, lColors[i].y, lColors[i].z );
851  lCoords[i] = SFVEC3F( pt.x, pt.y, pt.z );
852  }
853  }
854  else
855  {
856  for( size_t i = 0; i < vertices.size(); ++i )
857  {
858  ti = vertices[i];
859  glm::dvec4 pt( pCoords[ti].x, pCoords[ti].y, pCoords[ti].z, 1.0 );
860  pt = (*aTransform) * pt;
861  lCoords[i] = SFVEC3F( pt.x, pt.y, pt.z );
862  }
863  }
864 
865  m.m_VertexSize = (unsigned int) vertices.size();
866  m.m_Positions = lCoords;
867  unsigned int* lvidx = new unsigned int[ nvidx ];
868 
869  for( unsigned int i = 0; i < nvidx; ++i )
870  {
871  mit = indexmap.find( lv[i] );
872  lvidx[i] = mit->second;
873  }
874 
875  m.m_FaceIdxSize = (unsigned int )nvidx;
876  m.m_FaceIdx = lvidx;
877 
878  // set the per-vertex normals
879  size_t nNorms = 0;
880  SGVECTOR* pNorms = NULL;
881  double x, y, z;
882 
883  pn->GetNormalList( nNorms, pNorms );
884  SFVEC3F* lNorms = new SFVEC3F[ vertices.size() ];
885 
886  for( size_t i = 0; i < vertices.size(); ++i )
887  {
888  ti = vertices[i];
889  pNorms[ti].GetVector( x, y, z );
890  glm::dvec4 pt( x, y, z, 0.0 );
891  pt = (*aTransform) * pt;
892 
893  lNorms[i] = SFVEC3F( pt.x, pt.y, pt.z );
894  }
895 
896  m.m_Normals = lNorms;
897  meshes.push_back( m );
898 
899  return true;
900 }
SFVEC3F * m_Normals
Vertex normals array.
Definition: c3dmodel.h:80
SGCOORDINDEX * m_CoordIndices
Definition: sg_faceset.h:55
Class SGCOORDINDEX is a class which maintains a coordinate index list.
Definition: sg_coordindex.h:44
bool GetColorList(size_t &aListSize, SGCOLOR *&aColorList)
Definition: sg_colors.cpp:157
SGCOLORS * m_Colors
Definition: sg_faceset.h:53
bool GetMatIndex(MATLIST &aList, SGNODE *aNode, int &aIndex)
Definition: sg_node.cpp:313
SGFACESET * m_RFaceSet
Definition: sg_shape.h:52
bool GetCoordsList(size_t &aListSize, SGPOINT *&aCoordsList)
Definition: sg_coords.cpp:160
SFVEC3F * m_Positions
Vertex position array.
Definition: c3dmodel.h:79
Per-vertex normal/color/texcoors structure.
Definition: c3dmodel.h:76
SGCOLORS * m_RColors
Definition: sg_faceset.h:59
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:60
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:47
bool GetIndices(size_t &nIndices, int *&aIndexList)
Function GetIndices retrieves the number of indices and a pointer to the list.
Definition: sg_index.cpp:151
SFVEC3F * m_Color
Vertex color array, can be NULL.
Definition: c3dmodel.h:82
SGFACESET * m_FaceSet
Definition: sg_shape.h:48
bool validate(void)
Definition: sg_faceset.cpp:987
SGCOORDS * m_Coords
Definition: sg_faceset.h:54
void INIT_SMESH(SMESH &aMesh)
Definition: sg_node.cpp:366
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
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:51
void GetVector(double &aXVal, double &aYVal, double &aZVal) const
Definition: sg_base.cpp:283
SGNORMALS * m_Normals
Definition: sg_faceset.h:56
unsigned int * m_FaceIdx
Triangle Face Indexes.
Definition: c3dmodel.h:84
SGNORMALS * m_RNormals
Definition: sg_faceset.h:61
void GetColor(float &aRedVal, float &aGreenVal, float &aBlueVal) const
Definition: sg_base.cpp:65
bool GetNormalList(size_t &aListSize, SGVECTOR *&aNormalList)
Definition: sg_normals.cpp:158
bool SGSHAPE::ReadCache ( std::istream &  aFile,
SGNODE parentNode 
)
overridevirtual

Function ReadCache 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 511 of file sg_shape.cpp.

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

Referenced by SCENEGRAPH::ReadCache().

512 {
514  {
515  #ifdef DEBUG
516  std::ostringstream ostr;
517  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
518  ostr << " * [BUG] non-empty node";
519  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
520  #endif
521 
522  return false;
523  }
524 
525  #define NITEMS 4
526  bool items[NITEMS];
527 
528  for( int i = 0; i < NITEMS; ++i )
529  aFile.read( (char*)&items[i], sizeof(bool) );
530 
531  if( ( items[0] && items[1] ) || ( items[2] && items[3] ) )
532  {
533  #ifdef DEBUG
534  std::ostringstream ostr;
535  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
536  ostr << " * [INFO] corrupt data; multiple item definitions at position ";
537  ostr << aFile.tellg();
538  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
539  #endif
540 
541  return false;
542  }
543 
544  std::string name;
545 
546  if( items[0] )
547  {
548  if( S3D::SGTYPE_APPEARANCE != S3D::ReadTag( aFile, name ) )
549  {
550  #ifdef DEBUG
551  std::ostringstream ostr;
552  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
553  ostr << " * [INFO] corrupt data; bad child apperance tag at position ";
554  ostr << aFile.tellg();
555  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
556  #endif
557 
558  return false;
559  }
560 
561  m_Appearance = new SGAPPEARANCE( this );
562  m_Appearance->SetName( name.c_str() );
563 
564  if( !m_Appearance->ReadCache( aFile, this ) )
565  {
566  #ifdef DEBUG
567  std::ostringstream ostr;
568  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
569  ostr << " * [INFO] corrupt data while reading appearance '";
570  ostr << name << "'";
571  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
572  #endif
573 
574  return false;
575  }
576  }
577 
578  if( items[1] )
579  {
580  if( S3D::SGTYPE_APPEARANCE != S3D::ReadTag( aFile, name ) )
581  {
582  #ifdef DEBUG
583  std::ostringstream ostr;
584  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
585  ostr << " * [INFO] corrupt data; bad ref appearance tag at position ";
586  ostr << aFile.tellg();
587  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
588  #endif
589 
590  return false;
591  }
592 
593  SGNODE* np = FindNode( name.c_str(), this );
594 
595  if( !np )
596  {
597  #ifdef DEBUG
598  std::ostringstream ostr;
599  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
600  ostr << " * [INFO] corrupt data: cannot find ref appearance '";
601  ostr << name << "'";
602  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
603  #endif
604 
605  return false;
606  }
607 
608  if( S3D::SGTYPE_APPEARANCE != np->GetNodeType() )
609  {
610  #ifdef DEBUG
611  std::ostringstream ostr;
612  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
613  ostr << " * [INFO] corrupt data: type is not SGAPPEARANCE '";
614  ostr << name << "'";
615  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
616  #endif
617 
618  return false;
619  }
620 
622  m_RAppearance->addNodeRef( this );
623  }
624 
625  if( items[2] )
626  {
627  if( S3D::SGTYPE_FACESET != S3D::ReadTag( aFile, name ) )
628  {
629  #ifdef DEBUG
630  std::ostringstream ostr;
631  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
632  ostr << " * [INFO] corrupt data; bad child face set tag at position ";
633  ostr << aFile.tellg();
634  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
635  #endif
636 
637  return false;
638  }
639 
640  m_FaceSet = new SGFACESET( this );
641  m_FaceSet->SetName( name.c_str() );
642 
643  if( !m_FaceSet->ReadCache( aFile, this ) )
644  {
645  #ifdef DEBUG
646  std::ostringstream ostr;
647  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
648  ostr << " * [INFO] corrupt data while reading face set '";
649  ostr << name << "'";
650  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
651  #endif
652 
653  return false;
654  }
655  }
656 
657  if( items[3] )
658  {
659  if( S3D::SGTYPE_FACESET != S3D::ReadTag( aFile, name ) )
660  {
661  #ifdef DEBUG
662  std::ostringstream ostr;
663  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
664  ostr << " * [INFO] corrupt data; bad ref face set tag at position ";
665  ostr << aFile.tellg();
666  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
667  #endif
668 
669  return false;
670  }
671 
672  SGNODE* np = FindNode( name.c_str(), this );
673 
674  if( !np )
675  {
676  #ifdef DEBUG
677  std::ostringstream ostr;
678  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
679  ostr << " * [INFO] corrupt data: cannot find ref face set '";
680  ostr << name << "'";
681  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
682  #endif
683 
684  return false;
685  }
686 
687  if( S3D::SGTYPE_FACESET != np->GetNodeType() )
688  {
689  #ifdef DEBUG
690  std::ostringstream ostr;
691  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
692  ostr << " * [INFO] corrupt data: type is not SGFACESET '";
693  ostr << name << "'";
694  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
695  #endif
696 
697  return false;
698  }
699 
700  m_RFaceSet = (SGFACESET*)np;
701  m_RFaceSet->addNodeRef( this );
702  }
703 
704  if( aFile.fail() )
705  return false;
706 
707  return true;
708 }
void addNodeRef(SGNODE *aNode)
Function addNodeRef adds a pointer to a node which references, but does not own, this node...
Definition: sg_node.cpp:176
bool ReadCache(std::istream &aFile, SGNODE *parentNode) override
Function ReadCache Reads binary format data from a cache file.
SGFACESET * m_RFaceSet
Definition: sg_shape.h:52
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
bool ReadCache(std::istream &aFile, SGNODE *parentNode) override
Function ReadCache Reads binary format data from a cache file.
Definition: sg_faceset.cpp:673
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:47
S3D::SGTYPES ReadTag(std::istream &aFile, std::string &aName)
Function ReadTag reads the text tag of a binary cache file which is the NodeTag and unique ID number ...
Definition: sg_helpers.cpp:208
#define NITEMS
SGFACESET * m_FaceSet
Definition: sg_shape.h:48
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) override
Function FindNode searches the tree of linked nodes and returns a reference to the first node found w...
Definition: sg_shape.cpp:132
void SetName(const char *aName)
Definition: sg_node.cpp:159
const char * name
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:51
void SGSHAPE::ReNameNodes ( void  )
overridevirtual

Function ReNameNodes renames a node and all its child nodes in preparation for Write() operations.

Implements SGNODE.

Definition at line 339 of file sg_shape.cpp.

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

340 {
341  m_written = false;
342 
343  // rename this node
344  m_Name.clear();
345  GetName();
346 
347  // rename Appearance
348  if( m_Appearance )
350 
351  // rename FaceSet
352  if( m_FaceSet )
354 
355  return;
356 }
void ReNameNodes(void) override
Function ReNameNodes renames a node and all its child nodes in preparation for Write() operations...
void ReNameNodes(void) override
Function ReNameNodes renames a node and all its child nodes in preparation for Write() operations...
Definition: sg_faceset.cpp:458
const char * GetName(void)
Definition: sg_node.cpp:150
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:47
bool m_written
Definition: sg_node.h:86
SGFACESET * m_FaceSet
Definition: sg_shape.h:48
std::string m_Name
Definition: sg_node.h:85
void SGNODE::ResetNodeIndex ( void  )
inherited

Function ResetNodeIndex resets the global SG* node indices in preparation for Write() operations.

Definition at line 304 of file sg_node.cpp.

References node_counts, and S3D::SGTYPE_END.

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

305 {
306  for( int i = 0; i < (int)S3D::SGTYPE_END; ++i )
307  node_counts[i] = 1;
308 
309  return;
310 }
static unsigned int node_counts[S3D::SGTYPE_END]
Definition: sg_node.cpp:48
void SGNODE::SetName ( const char *  aName)
inherited

Definition at line 159 of file sg_node.cpp.

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

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

160 {
161  if( NULL == aName || 0 == aName[0] )
163  else
164  m_Name = aName;
165 
166  return;
167 }
std::string m_Name
Definition: sg_node.h:85
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
static void getNodeName(S3D::SGTYPES nodeType, std::string &aName)
Definition: sg_node.cpp:57
bool SGSHAPE::SetParent ( SGNODE aParent,
bool  notify = true 
)
overridevirtual

Function SetParent sets 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 102 of file sg_shape.cpp.

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

103 {
104  if( NULL != m_Parent )
105  {
106  if( aParent == m_Parent )
107  return true;
108 
109  // handle the change in parents
110  if( notify )
111  m_Parent->unlinkChildNode( this );
112 
113  m_Parent = NULL;
114 
115  if( NULL == aParent )
116  return true;
117  }
118 
119  // only a SGTRANSFORM may be parent to a SGSHAPE
120  if( NULL != aParent && S3D::SGTYPE_TRANSFORM != aParent->GetNodeType() )
121  return false;
122 
123  m_Parent = aParent;
124 
125  if( m_Parent )
126  m_Parent->AddChildNode( this );
127 
128  return true;
129 }
SGNODE * m_Parent
Definition: sg_node.h:83
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
virtual void unlinkChildNode(const SGNODE *aNode)=0
Function unlinkChild removes references to an owned child; it is invoked by the child upon destructio...
virtual bool AddChildNode(SGNODE *aNode)=0
bool SGNODE::SwapParent ( SGNODE aNewParent)
inherited

Function SwapParent swaps the ownership with the given parent.

This operation may be required when reordering nodes for optimization.

Parameters
aNewParent[in] will become the new parent to the object; it must be the same type as the parent of this instance.

Definition at line 120 of file sg_node.cpp.

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

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

121 {
122  if( aNewParent == m_Parent )
123  return true;
124 
125  if( NULL == aNewParent )
126  return false;
127 
128  if( NULL == m_Parent )
129  {
130  if( aNewParent->AddChildNode( this ) )
131  return true;
132 
133  return false;
134  }
135 
136  if( aNewParent->GetNodeType() != m_Parent->GetNodeType() )
137  return false;
138 
139  SGNODE* oldParent = m_Parent;
140  m_Parent->unlinkChildNode( this );
141  m_Parent = NULL;
142  aNewParent->unlinkRefNode( this );
143  aNewParent->AddChildNode( this );
144  oldParent->AddRefNode( this );
145 
146  return true;
147 }
virtual bool AddRefNode(SGNODE *aNode)=0
SGNODE * m_Parent
Definition: sg_node.h:83
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
virtual void unlinkRefNode(const SGNODE *aNode)=0
Function unlinkRef removes pointers to a referenced node; it is invoked by the referenced node upon d...
virtual void unlinkChildNode(const SGNODE *aNode)=0
Function unlinkChild removes references to an owned child; it is invoked by the child upon destructio...
virtual bool AddChildNode(SGNODE *aNode)=0
void SGSHAPE::unlinkChildNode ( const SGNODE aNode)
overridevirtual

Function unlinkChild removes references to an owned child; it 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 219 of file sg_shape.cpp.

References unlinkNode().

220 {
221  unlinkNode( aNode, true );
222  return;
223 }
void unlinkNode(const SGNODE *aNode, bool isChild)
Definition: sg_shape.cpp:170
void SGSHAPE::unlinkNode ( const SGNODE aNode,
bool  isChild 
)
private

Definition at line 170 of file sg_shape.cpp.

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

Referenced by unlinkChildNode(), and unlinkRefNode().

171 {
172  if( NULL == aNode )
173  return;
174 
175  if( isChild )
176  {
177  if( aNode == m_Appearance )
178  {
179  m_Appearance = NULL;
180  return;
181  }
182 
183  if( aNode == m_FaceSet )
184  {
185  m_FaceSet = NULL;
186  return;
187  }
188  }
189  else
190  {
191  if( aNode == m_RAppearance )
192  {
193  delNodeRef( this );
194  m_RAppearance = NULL;
195  return;
196  }
197 
198  if( aNode == m_RFaceSet )
199  {
200  delNodeRef( this );
201  m_RFaceSet = NULL;
202  return;
203  }
204  }
205 
206  #ifdef DEBUG
207  do {
208  std::ostringstream ostr;
209  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
210  ostr << " * [BUG] unlinkNode() did not find its target";
211  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
212  } while( 0 );
213  #endif
214 
215  return;
216 }
SGFACESET * m_RFaceSet
Definition: sg_shape.h:52
void delNodeRef(const SGNODE *aNode)
Function delNodeRef removes a pointer to a node which references, but does not own, this node.
Definition: sg_node.cpp:192
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:47
SGFACESET * m_FaceSet
Definition: sg_shape.h:48
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:51
void SGSHAPE::unlinkRefNode ( const SGNODE aNode)
overridevirtual

Function unlinkRef removes pointers to a referenced node; it 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 226 of file sg_shape.cpp.

References unlinkNode().

227 {
228  unlinkNode( aNode, false );
229  return;
230 }
void unlinkNode(const SGNODE *aNode, bool isChild)
Definition: sg_shape.cpp:170
bool SGSHAPE::WriteCache ( std::ostream &  aFile,
SGNODE parentNode 
)
overridevirtual

Function WriteCache write's 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 403 of file sg_shape.cpp.

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

404 {
405  if( NULL == parentNode )
406  {
407  if( NULL == m_Parent )
408  {
409  #ifdef DEBUG
410  std::ostringstream ostr;
411  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
412  ostr << " * [BUG] corrupt data; m_aParent is NULL";
413  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
414  #endif
415 
416  return false;
417  }
418 
419  SGNODE* np = m_Parent;
420 
421  while( NULL != np->GetParent() )
422  np = np->GetParent();
423 
424  if( np->WriteCache( aFile, NULL ) )
425  {
426  m_written = true;
427  return true;
428  }
429 
430  return false;
431  }
432 
433  if( parentNode != m_Parent )
434  {
435  #ifdef DEBUG
436  std::ostringstream ostr;
437  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
438  ostr << " * [BUG] corrupt data; parentNode != m_aParent";
439  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
440  #endif
441 
442  return false;
443  }
444 
445  if( !aFile.good() )
446  {
447  #ifdef DEBUG
448  std::ostringstream ostr;
449  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
450  ostr << " * [INFO] bad stream";
451  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
452  #endif
453 
454  return false;
455  }
456 
457  // check if any references are unwritten and swap parents if so
458  if( NULL != m_RAppearance && !m_RAppearance->isWritten() )
459  m_RAppearance->SwapParent(this);
460 
461  if( NULL != m_RFaceSet && !m_RFaceSet->isWritten() )
462  m_RFaceSet->SwapParent( this );
463 
464  aFile << "[" << GetName() << "]";
465  #define NITEMS 4
466  bool items[NITEMS];
467  int i;
468 
469  for( i = 0; i < NITEMS; ++i )
470  items[i] = 0;
471 
472  i = 0;
473  if( NULL != m_Appearance )
474  items[i] = true;
475 
476  ++i;
477  if( NULL != m_RAppearance )
478  items[i] = true;
479 
480  ++i;
481  if( NULL != m_FaceSet )
482  items[i] = true;
483 
484  ++i;
485  if( NULL != m_RFaceSet )
486  items[i] = true;
487 
488  for( int jj = 0; jj < NITEMS; ++jj )
489  aFile.write( (char*)&items[jj], sizeof(bool) );
490 
491  if( items[0] )
492  m_Appearance->WriteCache( aFile, this );
493 
494  if( items[1] )
495  aFile << "[" << m_RAppearance->GetName() << "]";
496 
497  if( items[2] )
498  m_FaceSet->WriteCache( aFile, this );
499 
500  if( items[3] )
501  aFile << "[" << m_RFaceSet->GetName() << "]";
502 
503  if( aFile.fail() )
504  return false;
505 
506  m_written = true;
507  return true;
508 }
SGNODE * m_Parent
Definition: sg_node.h:83
SGFACESET * m_RFaceSet
Definition: sg_shape.h:52
bool WriteCache(std::ostream &aFile, SGNODE *parentNode) override
Function WriteCache write's this node's data to a binary cache file; the data includes all data of ch...
Definition: sg_faceset.cpp:541
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
const char * GetName(void)
Definition: sg_node.cpp:150
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:47
bool m_written
Definition: sg_node.h:86
#define NITEMS
SGNODE * GetParent(void) const
Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no...
Definition: sg_node.cpp:114
bool SwapParent(SGNODE *aNewParent)
Function SwapParent swaps the ownership with the given parent.
Definition: sg_node.cpp:120
SGFACESET * m_FaceSet
Definition: sg_shape.h:48
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Function WriteCache write's this node's data to a binary cache file; the data includes all data of ch...
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:51
bool WriteCache(std::ostream &aFile, SGNODE *parentNode) override
Function WriteCache write's this node's data to a binary cache file; the data includes all data of ch...
bool isWritten(void)
Function IsWritten returns true if the object had already been written to a cache file or VRML file; ...
Definition: sg_node.h:130
bool SGSHAPE::WriteVRML ( std::ostream &  aFile,
bool  aReuseFlag 
)
overridevirtual

Function WriteVRML writes this node's data to a VRML file; this includes all data of child and referenced nodes.

Implements SGNODE.

Definition at line 359 of file sg_shape.cpp.

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

360 {
361  if( !m_Appearance && !m_RAppearance
362  && !m_FaceSet && !m_RFaceSet )
363  {
364  return false;
365  }
366 
367  if( aReuseFlag )
368  {
369  if( !m_written )
370  {
371  aFile << "DEF " << GetName() << " Shape {\n";
372  m_written = true;
373  }
374  else
375  {
376  aFile << " USE " << GetName() << "\n";
377  return true;
378  }
379  }
380  else
381  {
382  aFile << " Shape {\n";
383  }
384 
385  if( m_Appearance )
386  m_Appearance->WriteVRML( aFile, aReuseFlag );
387 
388  if( m_RAppearance )
389  m_RAppearance->WriteVRML( aFile, aReuseFlag );
390 
391  if( m_FaceSet )
392  m_FaceSet->WriteVRML( aFile, aReuseFlag );
393 
394  if( m_RFaceSet )
395  m_RFaceSet->WriteVRML( aFile, aReuseFlag );
396 
397  aFile << "}\n";
398 
399  return true;
400 }
SGFACESET * m_RFaceSet
Definition: sg_shape.h:52
const char * GetName(void)
Definition: sg_node.cpp:150
SGAPPEARANCE * m_Appearance
Definition: sg_shape.h:47
bool m_written
Definition: sg_node.h:86
SGFACESET * m_FaceSet
Definition: sg_shape.h:48
bool WriteVRML(std::ostream &aFile, bool aReuseFlag) override
Function WriteVRML writes this node's data to a VRML file; this includes all data of child and refere...
bool WriteVRML(std::ostream &aFile, bool aReuseFlag) override
Function WriteVRML writes this node's data to a VRML file; this includes all data of child and refere...
Definition: sg_faceset.cpp:485
SGAPPEARANCE * m_RAppearance
Definition: sg_shape.h:51

Member Data Documentation

SGAPPEARANCE* SGSHAPE::m_Appearance
std::list< SGNODE* > SGNODE::m_BackPointers
protectedinherited
SGFACESET* SGSHAPE::m_FaceSet
SGAPPEARANCE* SGSHAPE::m_RAppearance

Definition at line 51 of file sg_shape.h.

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

SGFACESET* SGSHAPE::m_RFaceSet

Definition at line 52 of file sg_shape.h.

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


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