KiCad PCB EDA Suite
SGNORMALS Class Reference

Define a set of vertex normals for a scene graph object. More...

#include <sg_normals.h>

Inheritance diagram for SGNORMALS:
SGNODE

Public Member Functions

 SGNORMALS (SGNODE *aParent)
 
virtual ~SGNORMALS ()
 
virtual bool SetParent (SGNODE *aParent, bool notify=true) override
 Set the parent SGNODE of this object. More...
 
SGNODEFindNode (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. More...
 
bool AddRefNode (SGNODE *aNode) noexcept override
 
bool AddChildNode (SGNODE *aNode) noexcept override
 
bool GetNormalList (size_t &aListSize, SGVECTOR *&aNormalList)
 
void SetNormalList (size_t aListSize, const SGVECTOR *aNormalList)
 
void AddNormal (double aXValue, double aYValue, double aZValue)
 
void AddNormal (const SGVECTOR &aNormal)
 
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...
 
void unlinkChildNode (const SGNODE *aNode) noexcept override
 Remove references to an owned child. More...
 
void unlinkRefNode (const SGNODE *aNode) noexcept 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

std::vector< SGVECTORnorms
 

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

Detailed Description

Define a set of vertex normals for a scene graph object.

Definition at line 38 of file sg_normals.h.

Constructor & Destructor Documentation

◆ SGNORMALS()

SGNORMALS::SGNORMALS ( SGNODE aParent)

Definition at line 33 of file sg_normals.cpp.

33  : SGNODE( aParent )
34 {
36 
37  if( nullptr != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
38  {
39  m_Parent = nullptr;
40 
41  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] inappropriate parent to SGNORMALS (type %d)",
42  __FILE__, __FUNCTION__, __LINE__, aParent->GetNodeType() );
43  }
44  else if( nullptr != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
45  {
46  m_Parent->AddChildNode( this );
47  }
48 }
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
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
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, SGNODE::m_SGtype, S3D::SGTYPE_FACESET, and S3D::SGTYPE_NORMALS.

◆ ~SGNORMALS()

SGNORMALS::~SGNORMALS ( )
virtual

Definition at line 51 of file sg_normals.cpp.

52 {
53  norms.clear();
54 }
std::vector< SGVECTOR > norms
Definition: sg_normals.h:64

References norms.

Member Function Documentation

◆ AddChildNode()

bool SGNORMALS::AddChildNode ( SGNODE aNode)
overridevirtualnoexcept

Implements SGNODE.

Definition at line 119 of file sg_normals.cpp.

120 {
121  wxCHECK( false, false );
122 
123  return false;
124 }

◆ 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 SGSHAPE::addNode(), SGFACESET::addNode(), SGSHAPE::ReadCache(), and SGFACESET::ReadCache().

◆ AddNormal() [1/2]

void SGNORMALS::AddNormal ( double  aXValue,
double  aYValue,
double  aZValue 
)

Definition at line 154 of file sg_normals.cpp.

155 {
156  norms.emplace_back( aXValue, aYValue, aZValue );
157 }
std::vector< SGVECTOR > norms
Definition: sg_normals.h:64

References norms.

◆ AddNormal() [2/2]

void SGNORMALS::AddNormal ( const SGVECTOR aNormal)

Definition at line 160 of file sg_normals.cpp.

161 {
162  norms.push_back( aNormal );
163 }
std::vector< SGVECTOR > norms
Definition: sg_normals.h:64

References norms.

◆ AddRefNode()

bool SGNORMALS::AddRefNode ( SGNODE aNode)
overridevirtualnoexcept

Implements SGNODE.

Definition at line 111 of file sg_normals.cpp.

112 {
113  wxCHECK( false, false );
114 
115  return false;
116 }

◆ 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_SHAPE::Attach(), IFSG_COORDINDEX::Attach(), IFSG_NORMALS::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_COORDINDEX::NewNode(), IFSG_COORDS::NewNode(), IFSG_FACESET::NewNode(), IFSG_NORMALS::NewNode(), IFSG_SHAPE::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 SGSHAPE::unlinkNode(), SGFACESET::unlinkNode(), SGFACESET::~SGFACESET(), and SGSHAPE::~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_NORMALS::Attach(), IFSG_FACESET::Attach(), IFSG_COORDS::Attach(), IFSG_SHAPE::Attach(), IFSG_COLORS::Attach(), IFSG_TRANSFORM::Attach(), IFSG_NODE::Destroy(), IFSG_APPEARANCE::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDS::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_NORMALS::NewNode(), IFSG_FACESET::NewNode(), IFSG_COLORS::NewNode(), IFSG_TRANSFORM::NewNode(), and IFSG_NODE::~IFSG_NODE().

◆ FindNode()

SGNODE * SGNORMALS::FindNode ( const char *  aNodeName,
const SGNODE aCaller 
)
overridevirtualnoexcept

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

88 {
89  if( nullptr == aNodeName || 0 == aNodeName[0] )
90  return nullptr;
91 
92  if( !m_Name.compare( aNodeName ) )
93  return this;
94 
95  return nullptr;
96 }
std::string m_Name
name to use for referencing the entity by name.
Definition: sg_node.h:229

Referenced by SGFACESET::FindNode().

◆ 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_COORDINDEX::NewNode(), IFSG_COORDS::NewNode(), IFSG_SHAPE::NewNode(), IFSG_FACESET::NewNode(), IFSG_NORMALS::NewNode(), IFSG_COLORS::NewNode(), and IFSG_TRANSFORM::NewNode().

◆ GetNormalList()

bool SGNORMALS::GetNormalList ( size_t &  aListSize,
SGVECTOR *&  aNormalList 
)

Definition at line 127 of file sg_normals.cpp.

128 {
129  if( norms.empty() )
130  {
131  aListSize = 0;
132  aNormalList = nullptr;
133  return false;
134  }
135 
136  aListSize = norms.size();
137  aNormalList = &norms[0];
138  return true;
139 }
std::vector< SGVECTOR > norms
Definition: sg_normals.h:64

References norms.

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

◆ 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_NORMALS::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDS::NewNode(), IFSG_FACESET::NewNode(), IFSG_COLORS::NewNode(), IFSG_TRANSFORM::NewNode(), SGSHAPE::WriteCache(), WriteCache(), SGCOLORS::WriteCache(), SCENEGRAPH::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 SGSHAPE::WriteCache(), SCENEGRAPH::WriteCache(), and SGFACESET::WriteCache().

◆ ReadCache()

bool SGNORMALS::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 277 of file sg_normals.cpp.

278 {
279  wxCHECK( norms.empty(), false );
280 
281  size_t npts;
282  aFile.read( (char*) &npts, sizeof( size_t ) );
283  SGVECTOR tmp;
284 
285  if( aFile.fail() )
286  return false;
287 
288  for( size_t i = 0; i < npts; ++i )
289  {
290  if( !S3D::ReadVector( aFile, tmp ) || aFile.fail() )
291  return false;
292 
293  norms.push_back( tmp );
294  }
295 
296  return true;
297 }
bool ReadVector(std::istream &aFile, SGVECTOR &aVector)
Definition: sg_helpers.cpp:279
std::vector< SGVECTOR > norms
Definition: sg_normals.h:64

References norms, and S3D::ReadVector().

Referenced by SGFACESET::ReadCache().

◆ ReNameNodes()

void SGNORMALS::ReNameNodes ( void  )
overridevirtual

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

Implements SGNODE.

Definition at line 166 of file sg_normals.cpp.

167 {
168  m_written = false;
169 
170  // rename this node
171  m_Name.clear();
172  GetName();
173 }
const char * GetName(void)
Definition: sg_node.cpp:146
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230
std::string m_Name
name to use for referencing the entity by name.
Definition: sg_node.h:229

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

Referenced by SGFACESET::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 SGSHAPE::ReadCache(), SCENEGRAPH::ReadCache(), SGFACESET::ReadCache(), and IFSG_NODE::SetName().

◆ SetNormalList()

void SGNORMALS::SetNormalList ( size_t  aListSize,
const SGVECTOR aNormalList 
)

Definition at line 142 of file sg_normals.cpp.

143 {
144  norms.clear();
145 
146  if( 0 == aListSize || nullptr == aNormalList )
147  return;
148 
149  for( int i = 0; i < (int)aListSize; ++i )
150  norms.push_back( aNormalList[i] );
151 }
std::vector< SGVECTOR > norms
Definition: sg_normals.h:64

References norms.

◆ SetParent()

bool SGNORMALS::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 57 of file sg_normals.cpp.

58 {
59  if( nullptr != 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 = nullptr;
69 
70  if( nullptr == aParent )
71  return true;
72  }
73 
74  // only a SGFACESET may be parent to a SGNORMALS
75  if( nullptr != 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
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_FACESET, and SGNODE::unlinkChildNode().

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

◆ 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 SGSHAPE::WriteCache(), and SGFACESET::WriteCache().

◆ unlinkChildNode()

void SGNORMALS::unlinkChildNode ( const SGNODE aNode)
overridevirtualnoexcept

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

100 {
101  wxCHECK( false, /* void */ );
102 }

◆ unlinkRefNode()

void SGNORMALS::unlinkRefNode ( const SGNODE aNode)
overridevirtualnoexcept

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 105 of file sg_normals.cpp.

106 {
107  wxCHECK( false, /* void */ );
108 }

◆ WriteCache()

bool SGNORMALS::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 232 of file sg_normals.cpp.

233 {
234  if( nullptr == parentNode )
235  {
236  wxCHECK( m_Parent, false );
237 
238  SGNODE* np = m_Parent;
239 
240  while( nullptr != np->GetParent() )
241  np = np->GetParent();
242 
243  if( np->WriteCache( aFile, nullptr ) )
244  {
245  m_written = true;
246  return true;
247  }
248 
249  return false;
250  }
251 
252  wxCHECK( parentNode == m_Parent, false );
253 
254  if( !aFile.good() )
255  {
256  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] bad stream",
257  __FILE__, __FUNCTION__, __LINE__ );
258 
259  return false;
260  }
261 
262  aFile << "[" << GetName() << "]";
263  size_t npts = norms.size();
264  aFile.write( (char*)&npts, sizeof(size_t) );
265 
266  for( size_t i = 0; i < npts; ++i )
267  S3D::WriteVector( aFile, norms[i] );
268 
269  if( aFile.fail() )
270  return false;
271 
272  m_written = true;
273  return true;
274 }
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
const char * GetName(void)
Definition: sg_node.cpp:146
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230
bool WriteVector(std::ostream &aFile, const SGVECTOR &aVector)
Definition: sg_helpers.cpp:165
std::vector< SGVECTOR > norms
Definition: sg_normals.h:64
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.

References SGNODE::GetName(), SGNODE::GetParent(), SGNODE::m_Parent, SGNODE::m_written, norms, SGNODE::WriteCache(), and S3D::WriteVector().

Referenced by SGFACESET::WriteCache().

◆ WriteVRML()

bool SGNORMALS::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 176 of file sg_normals.cpp.

177 {
178  if( norms.empty() )
179  return false;
180 
181  if( aReuseFlag )
182  {
183  if( !m_written )
184  {
185  aFile << " normal DEF " << GetName() << " Normal { vector [\n ";
186  m_written = true;
187  }
188  else
189  {
190  aFile << " normal USE " << GetName() << "\n";
191  return true;
192  }
193  }
194  else
195  {
196  aFile << " normal Normal { vector [\n ";
197  }
198 
199  std::string tmp;
200  size_t n = norms.size();
201  bool nline = false;
202 
203  for( size_t i = 0; i < n; )
204  {
205  S3D::FormatVector( tmp, norms[i] );
206  aFile << tmp ;
207  ++i;
208 
209  if( i < n )
210  {
211  aFile << ",";
212 
213  if( nline )
214  {
215  aFile << "\n ";
216  nline = false;
217  }
218  else
219  {
220  nline = true;
221  }
222 
223  }
224  }
225 
226  aFile << "] }\n";
227 
228  return true;
229 }
void FormatVector(std::string &result, const SGVECTOR &aVector)
Definition: sg_helpers.cpp:118
const char * GetName(void)
Definition: sg_node.cpp:146
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230
std::vector< SGVECTOR > norms
Definition: sg_normals.h:64

References S3D::FormatVector(), SGNODE::GetName(), SGNODE::m_written, and norms.

Referenced by SGFACESET::WriteVRML().

Member Data Documentation

◆ 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_Name

◆ m_Parent

◆ m_SGtype

◆ m_written

◆ norms


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