KiCad PCB EDA Suite
SGCOORDINDEX Class Reference

Class SGCOORDINDEX is a class which maintains a coordinate index list. More...

#include <sg_coordindex.h>

Inheritance diagram for SGCOORDINDEX:
SGINDEX SGNODE

Public Member Functions

 SGCOORDINDEX (SGNODE *aParent)
 
virtual ~SGCOORDINDEX ()
 
void GatherCoordIndices (std::vector< int > &aIndexList)
 Function GatherCoordIndices adds all coordinate indices to the given list in preparation for a normals calculation. More...
 
void unlinkChildNode (const SGNODE *aCaller) 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 *aCaller) 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...
 
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
 
bool GetIndices (size_t &nIndices, int *&aIndexList)
 Function GetIndices retrieves the number of indices and a pointer to the list. More...
 
void SetIndices (size_t nIndices, int *aIndexList)
 Function SetIndices sets the number of indices and creates a copy of the given index data. More...
 
void AddIndex (int aIndex)
 Function AddIndex adds a single index to the list. More...
 
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...
 
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

std::vector< int > index
 

Protected Member Functions

bool writeCoordIndex (std::ostream &aFile)
 
bool writeColorIndex (std::ostream &aFile)
 
bool writeIndexList (std::ostream &aFile)
 

Protected Attributes

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

Detailed Description

Class SGCOORDINDEX is a class which maintains a coordinate index list.

Users must ensure that coordinate indices are specified as triplets (triangular faces) since no checking is performed. In instances where it is not possible to determine which side of the triangle is to be rendered (for example IGES entities) then the user must supply each triplet in both point orders.

Definition at line 44 of file sg_coordindex.h.

Constructor & Destructor Documentation

SGCOORDINDEX::SGCOORDINDEX ( SGNODE aParent)

Definition at line 27 of file sg_coordindex.cpp.

References SGNODE::AddChildNode(), SGNODE::GetNodeType(), SGNODE::m_Parent, SGNODE::m_SGtype, S3D::SGTYPE_COORDINDEX, and S3D::SGTYPE_FACESET.

27  : SGINDEX( aParent )
28 {
30 
31  if( NULL != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
32  {
33  m_Parent->AddChildNode( this );
34  }
35 
36  return;
37 }
SGINDEX(SGNODE *aParent)
Definition: sg_index.cpp:31
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
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
virtual bool AddChildNode(SGNODE *aNode)=0
SGCOORDINDEX::~SGCOORDINDEX ( )
virtual

Definition at line 40 of file sg_coordindex.cpp.

41 {
42  return;
43 }

Member Function Documentation

bool SGINDEX::AddChildNode ( SGNODE aNode)
overridevirtualinherited

Implements SGNODE.

Definition at line 138 of file sg_index.cpp.

139 {
140  #ifdef DEBUG
141  std::ostringstream ostr;
142  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
143  ostr << " * [BUG] this node does not accept children or refs";
144  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
145  #endif
146 
147  return false;
148 }
void SGINDEX::AddIndex ( int  aIndex)
inherited

Function AddIndex adds a single index to the list.

Parameters
nIndices[in] the number of indices to be stored
aIndexList[in] the index data

Definition at line 180 of file sg_index.cpp.

References SGINDEX::index.

181 {
182  index.push_back( aIndex );
183  return;
184 }
std::vector< int > index
Definition: sg_index.h:44
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 SGSHAPE::addNode(), SGFACESET::addNode(), SGSHAPE::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 SGINDEX::AddRefNode ( SGNODE aNode)
overridevirtualinherited

Implements SGNODE.

Definition at line 125 of file sg_index.cpp.

126 {
127  #ifdef DEBUG
128  std::ostringstream ostr;
129  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
130  ostr << " * [BUG] this node does not accept children or refs";
131  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
132  #endif
133 
134  return false;
135 }
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 SGSHAPE::unlinkNode(), SGFACESET::unlinkNode(), SGFACESET::~SGFACESET(), and SGSHAPE::~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 * SGINDEX::FindNode ( const char *  aNodeName,
const SGNODE aCaller 
)
overridevirtualinherited

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 87 of file sg_index.cpp.

References SGNODE::m_Name.

Referenced by SGFACESET::FindNode().

88 {
89  if( NULL == aNodeName || 0 == aNodeName[0] )
90  return NULL;
91 
92  if( !m_Name.compare( aNodeName ) )
93  return this;
94 
95  return NULL;
96 }
std::string m_Name
Definition: sg_node.h:85
void SGCOORDINDEX::GatherCoordIndices ( std::vector< int > &  aIndexList)

Function GatherCoordIndices adds all coordinate indices to the given list in preparation for a normals calculation.

Definition at line 46 of file sg_coordindex.cpp.

References SGINDEX::index.

Referenced by SGFACESET::GatherCoordIndices().

47 {
48  if( index.empty() )
49  return;
50 
51  aIndexList.insert( aIndexList.end(), index.begin(), index.end() );
52 
53  return;
54 }
std::vector< int > index
Definition: sg_index.h:44
bool SGINDEX::GetIndices ( size_t &  nIndices,
int *&  aIndexList 
)
inherited

Function GetIndices retrieves the number of indices and a pointer to the list.

Note: the returned pointer may be invalidated by future operations on the SGNODE; the caller must make immediate use of the data and must not rely on the pointer's validity in the future.

Parameters
nIndices[out] will hold the number of indices in the list
aIndexList[out] will store a pointer to the data
Returns
true if there was available data (nIndices > 0) otherwise false

Definition at line 151 of file sg_index.cpp.

References SGINDEX::index.

Referenced by SGSHAPE::Prepare(), and SGFACESET::validate().

152 {
153  if( index.empty() )
154  {
155  nIndices = 0;
156  aIndexList = NULL;
157  return false;
158  }
159 
160  nIndices = index.size();
161  aIndexList = & index[0];
162  return true;
163 }
std::vector< int > index
Definition: sg_index.h:44
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 SGSHAPE::WriteCache(), SGFACESET::WriteCache(), and SCENEGRAPH::WriteCache().

131  {
132  return m_written;
133  }
bool m_written
Definition: sg_node.h:86
bool SGINDEX::ReadCache ( std::istream &  aFile,
SGNODE parentNode 
)
overridevirtualinherited

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 366 of file sg_index.cpp.

References SGINDEX::index.

Referenced by SGFACESET::ReadCache().

367 {
368  if( !index.empty() )
369  {
370  #ifdef DEBUG
371  std::ostringstream ostr;
372  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
373  ostr << " * [BUG] non-empty node";
374  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
375  #endif
376 
377  return false;
378  }
379 
380  size_t npts;
381  aFile.read( (char*)&npts, sizeof(size_t) );
382  int tmp;
383 
384  if( aFile.fail() )
385  return false;
386 
387  for( size_t i = 0; i < npts; ++i )
388  {
389  aFile.read( (char*)&tmp, sizeof(int) );
390 
391  if( aFile.fail() )
392  return false;
393 
394  index.push_back( tmp );
395  }
396 
397  return true;
398 }
std::vector< int > index
Definition: sg_index.h:44
void SGINDEX::ReNameNodes ( void  )
overridevirtualinherited

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

Implements SGNODE.

Definition at line 187 of file sg_index.cpp.

References SGNODE::GetName(), SGNODE::m_Name, and SGNODE::m_written.

Referenced by SGFACESET::ReNameNodes().

188 {
189  m_written = false;
190 
191  // rename this node
192  m_Name.clear();
193  GetName();
194 }
const char * GetName(void)
Definition: sg_node.cpp:150
bool m_written
Definition: sg_node.h:86
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 SGINDEX::SetIndices ( size_t  nIndices,
int *  aIndexList 
)
inherited

Function SetIndices sets the number of indices and creates a copy of the given index data.

Parameters
nIndices[in] the number of indices to be stored
aIndexList[in] the index data

Definition at line 166 of file sg_index.cpp.

References SGINDEX::index.

167 {
168  index.clear();
169 
170  if( 0 == nIndices || NULL == aIndexList )
171  return;
172 
173  for( size_t i = 0; i < nIndices; ++i )
174  index.push_back( aIndexList[i] );
175 
176  return;
177 }
std::vector< int > index
Definition: sg_index.h:44
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 SGSHAPE::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 SGINDEX::SetParent ( SGNODE aParent,
bool  notify = true 
)
overridevirtualinherited

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 57 of file sg_index.cpp.

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

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

58 {
59  if( NULL != m_Parent )
60  {
61  if( aParent == m_Parent )
62  return true;
63 
64  // handle the change in parents
65  if( notify )
66  m_Parent->unlinkChildNode( this );
67 
68  m_Parent = NULL;
69 
70  if( NULL == aParent )
71  return true;
72  }
73 
74  // only a SGFACESET may be parent to a SGINDEX and derived types
75  if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
76  return false;
77 
78  m_Parent = aParent;
79 
80  if( m_Parent )
81  m_Parent->AddChildNode( this );
82 
83  return true;
84 }
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 SGSHAPE::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 SGINDEX::unlinkChildNode ( const SGNODE aNode)
overridevirtualinherited

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 99 of file sg_index.cpp.

100 {
101  #ifdef DEBUG
102  std::ostringstream ostr;
103  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
104  ostr << " * [BUG] unexpected code branch; node should have no children or refs";
105  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
106  #endif
107 
108  return;
109 }
void SGINDEX::unlinkRefNode ( const SGNODE aNode)
overridevirtualinherited

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 112 of file sg_index.cpp.

113 {
114  #ifdef DEBUG
115  std::ostringstream ostr;
116  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
117  ostr << " * [BUG] unexpected code branch; node should have no children or refs";
118  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
119  #endif
120 
121  return;
122 }
bool SGINDEX::WriteCache ( std::ostream &  aFile,
SGNODE parentNode 
)
overridevirtualinherited

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 297 of file sg_index.cpp.

References SGNODE::GetName(), SGNODE::GetParent(), SGINDEX::index, SGNODE::m_Parent, SGNODE::m_written, and SGNODE::WriteCache().

Referenced by SGFACESET::WriteCache().

298 {
299  if( NULL == parentNode )
300  {
301  if( NULL == m_Parent )
302  {
303  #ifdef DEBUG
304  std::ostringstream ostr;
305  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
306  ostr << " * [BUG] corrupt data; m_aParent is NULL";
307  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
308  #endif
309 
310  return false;
311  }
312 
313  SGNODE* np = m_Parent;
314 
315  while( NULL != np->GetParent() )
316  np = np->GetParent();
317 
318  if( np->WriteCache( aFile, NULL ) )
319  {
320  m_written = true;
321  return true;
322  }
323 
324  return false;
325  }
326 
327  if( parentNode != m_Parent )
328  {
329  #ifdef DEBUG
330  std::ostringstream ostr;
331  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
332  ostr << " * [BUG] corrupt data; parentNode != m_aParent";
333  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
334  #endif
335 
336  return false;
337  }
338 
339  if( !aFile.good() )
340  {
341  #ifdef DEBUG
342  std::ostringstream ostr;
343  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
344  ostr << " * [INFO] bad stream";
345  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
346  #endif
347 
348  return false;
349  }
350 
351  aFile << "[" << GetName() << "]";
352  size_t npts = index.size();
353  aFile.write( (char*)&npts, sizeof(size_t) );
354 
355  for( size_t i = 0; i < npts; ++i )
356  aFile.write( (char*)&index[i], sizeof(int) );
357 
358  if( aFile.fail() )
359  return false;
360 
361  m_written = true;
362  return true;
363 }
SGNODE * m_Parent
Definition: sg_node.h:83
std::vector< int > index
Definition: sg_index.h:44
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
bool m_written
Definition: sg_node.h:86
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
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...
bool SGINDEX::writeColorIndex ( std::ostream &  aFile)
protectedinherited

Definition at line 261 of file sg_index.cpp.

References SGINDEX::writeIndexList().

Referenced by SGINDEX::WriteVRML().

262 {
263  aFile << " colorIndex [\n ";
264  return writeIndexList( aFile );
265 }
bool writeIndexList(std::ostream &aFile)
Definition: sg_index.cpp:268
bool SGINDEX::writeCoordIndex ( std::ostream &  aFile)
protectedinherited

Definition at line 209 of file sg_index.cpp.

References SGINDEX::index.

Referenced by SGINDEX::WriteVRML().

210 {
211  size_t n = index.size();
212 
213  if( n % 3 )
214  {
215  #ifdef DEBUG
216  std::ostringstream ostr;
217  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
218  ostr << " * [BUG] coord index is not divisible by three (violates triangle constraint)";
219  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
220  #endif
221 
222  return false;
223  }
224 
225  aFile << " coordIndex [\n ";
226 
227  // indices to control formatting
228  int nv0 = 0;
229  int nv1 = 0;
230 
231  for( size_t i = 0; i < n; )
232  {
233  aFile << index[i];
234  ++i;
235 
236  if( ++nv0 == 3 )
237  {
238  aFile << ",-1";
239  ++nv1;
240  nv0 = 0;
241  }
242 
243  if( i < n )
244  {
245  aFile << ",";
246 
247  if( nv1 == 8 )
248  {
249  nv1 = 0;
250  aFile << "\n ";
251  }
252  }
253  }
254 
255  aFile << "]\n";
256 
257  return true;
258 }
std::vector< int > index
Definition: sg_index.h:44
bool SGINDEX::writeIndexList ( std::ostream &  aFile)
protectedinherited

Definition at line 268 of file sg_index.cpp.

References SGINDEX::index.

Referenced by SGINDEX::writeColorIndex().

269 {
270  // index to control formatting
271  int nv = 0;
272  size_t n = index.size();
273 
274  for( size_t i = 0; i < n; )
275  {
276  aFile << index[i];
277  ++i;
278 
279  if( i < n )
280  {
281  aFile << ",";
282 
283  if( ++nv == 20 )
284  {
285  aFile << "\n ";
286  nv = 0;
287  }
288  }
289  }
290 
291  aFile << "]\n";
292 
293  return true;
294 }
std::vector< int > index
Definition: sg_index.h:44
bool SGINDEX::WriteVRML ( std::ostream &  aFile,
bool  aReuseFlag 
)
overridevirtualinherited

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 197 of file sg_index.cpp.

References SGINDEX::index, SGNODE::m_SGtype, S3D::SGTYPE_COORDINDEX, SGINDEX::writeColorIndex(), and SGINDEX::writeCoordIndex().

Referenced by SGFACESET::WriteVRML().

198 {
199  if( index.empty() )
200  return false;
201 
203  return writeCoordIndex( aFile );
204 
205  return writeColorIndex( aFile );
206 }
bool writeColorIndex(std::ostream &aFile)
Definition: sg_index.cpp:261
std::vector< int > index
Definition: sg_index.h:44
bool writeCoordIndex(std::ostream &aFile)
Definition: sg_index.cpp:209
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84

Member Data Documentation

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

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