KiCad PCB EDA Suite
SGAPPEARANCE Class Reference

Defines the generic material appearance of a scenegraph object. More...

#include <sg_appearance.h>

Inheritance diagram for SGAPPEARANCE:
SGNODE

Public Member Functions

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...
 
 SGAPPEARANCE (SGNODE *aParent)
 
virtual ~SGAPPEARANCE ()
 
virtual bool SetParent (SGNODE *aParent, bool notify=true) override
 Set the parent SGNODE of this object. More...
 
bool SetEmissive (float aRVal, float aGVal, float aBVal)
 
bool SetEmissive (const SGCOLOR *aRGBColor)
 
bool SetEmissive (const SGCOLOR &aRGBColor)
 
bool SetDiffuse (float aRVal, float aGVal, float aBVal)
 
bool SetDiffuse (const SGCOLOR *aRGBColor)
 
bool SetDiffuse (const SGCOLOR &aRGBColor)
 
bool SetSpecular (float aRVal, float aGVal, float aBVal)
 
bool SetSpecular (const SGCOLOR *aRGBColor)
 
bool SetSpecular (const SGCOLOR &aRGBColor)
 
bool SetAmbient (float aRVal, float aGVal, float aBVal)
 
bool SetAmbient (const SGCOLOR *aRGBColor)
 
bool SetAmbient (const SGCOLOR &aRGBColor)
 
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
 
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...
 
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

float shininess
 
float transparency
 
SGCOLOR ambient
 
SGCOLOR diffuse
 
SGCOLOR emissive
 
SGCOLOR specular
 

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

Defines the generic material appearance of a scenegraph object.

Definition at line 37 of file sg_appearance.h.

Constructor & Destructor Documentation

◆ SGAPPEARANCE()

SGAPPEARANCE::SGAPPEARANCE ( SGNODE aParent)

Definition at line 34 of file sg_appearance.cpp.

34  : SGNODE( aParent )
35 {
37 
38  // defaults in accord with VRML2.0 spec
39  ambient.SetColor( 0.05317f, 0.17879f, 0.01804f );
40  shininess = 0.2f;
41  transparency = 0.0f;
42  diffuse.SetColor( 0.8f, 0.8f, 0.8f );
43 
44  if( nullptr != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
45  {
46  m_Parent = nullptr;
47 
48  wxLogTrace( MASK_3D_SG,
49  wxT( "%s:%s:%d * [BUG] inappropriate parent to SGAPPEARANCE (type %s )" ),
50  __FILE__, __FUNCTION__, __LINE__, aParent->GetNodeType() );
51  }
52  else if( nullptr != aParent && S3D::SGTYPE_SHAPE == aParent->GetNodeType() )
53  {
54  m_Parent->AddChildNode( this );
55  }
56 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR ambient
Definition: sg_appearance.h:76
float transparency
Definition: sg_appearance.h:75
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(), ambient, diffuse, SGNODE::GetNodeType(), SGNODE::m_Parent, SGNODE::m_SGtype, SGCOLOR::SetColor(), S3D::SGTYPE_APPEARANCE, S3D::SGTYPE_SHAPE, shininess, and transparency.

◆ ~SGAPPEARANCE()

SGAPPEARANCE::~SGAPPEARANCE ( )
virtual

Definition at line 59 of file sg_appearance.cpp.

60 {
61 }

Member Function Documentation

◆ AddChildNode()

bool SGAPPEARANCE::AddChildNode ( SGNODE aNode)
overridevirtualnoexcept

Implements SGNODE.

Definition at line 208 of file sg_appearance.cpp.

209 {
210  wxCHECK_MSG( aNode, false, wxT( "this node does not accept children or refs" ) );
211 
212  // This is redundant but it keeps gcc from generating a warning on debug builds.
213  return false;
214 }

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

◆ AddRefNode()

bool SGAPPEARANCE::AddRefNode ( SGNODE aNode)
overridevirtualnoexcept

Implements SGNODE.

Definition at line 199 of file sg_appearance.cpp.

200 {
201  wxCHECK_MSG( aNode, false, wxT( "this node does not accept children or refs" ) );
202 
203  // This is redundant but it keeps gcc from generating a warning on debug builds.
204  return false;
205 }

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

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

Referenced by S3D::AssociateSGNodeWrapper(), IFSG_APPEARANCE::Attach(), IFSG_NORMALS::Attach(), IFSG_SHAPE::Attach(), IFSG_COORDINDEX::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_NORMALS::NewNode(), IFSG_FACESET::NewNode(), IFSG_COORDS::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDINDEX::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, wxT( "%s:%s:%d * [BUG] delNodeRef() did not find its target, this "
200  "node type %d, referenced node type %d" ),
201  __FILE__, __FUNCTION__, __LINE__,
202  m_SGtype,
203  aNode->GetNodeType() );
204 }
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 225 of file sg_node.cpp.

226 {
227  if( !m_Association )
228  return;
229 
230  wxCHECK( aWrapperRef, /* void */ );
231 
232  wxCHECK( *aWrapperRef == *m_Association && aWrapperRef == m_Association, /* void */ );
233 
234  m_Association = nullptr;
235 }
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_COORDS::Attach(), IFSG_NORMALS::Attach(), IFSG_FACESET::Attach(), IFSG_SHAPE::Attach(), IFSG_COLORS::Attach(), IFSG_TRANSFORM::Attach(), IFSG_NODE::Destroy(), IFSG_APPEARANCE::NewNode(), IFSG_COORDS::NewNode(), IFSG_SHAPE::NewNode(), IFSG_FACESET::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_NORMALS::NewNode(), IFSG_COLORS::NewNode(), IFSG_TRANSFORM::NewNode(), and IFSG_NODE::~IFSG_NODE().

◆ FindNode()

SGNODE * SGAPPEARANCE::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 173 of file sg_appearance.cpp.

174 {
175  if( nullptr == aNodeName || 0 == aNodeName[0] )
176  return nullptr;
177 
178  if( !m_Name.compare( aNodeName ) )
179  return this;
180 
181  return nullptr;
182 }
std::string m_Name
name to use for referencing the entity by name.
Definition: sg_node.h:229

Referenced by SGSHAPE::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_NORMALS::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_FACESET::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDS::NewNode(), IFSG_COLORS::NewNode(), and IFSG_TRANSFORM::NewNode().

◆ GetParent()

SGNODE * SGNODE::GetParent ( void  ) const
noexceptinherited

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

top level transform).

Definition at line 110 of file sg_node.cpp.

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

Referenced by IFSG_NODE::GetParent(), S3D::GetSGNodeParent(), IFSG_APPEARANCE::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_FACESET::NewNode(), IFSG_NORMALS::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDS::NewNode(), IFSG_COLORS::NewNode(), IFSG_TRANSFORM::NewNode(), SGSHAPE::WriteCache(), SGNORMALS::WriteCache(), SCENEGRAPH::WriteCache(), SGCOLORS::WriteCache(), SGFACESET::WriteCache(), SGCOORDS::WriteCache(), 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 SGAPPEARANCE::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 350 of file sg_appearance.cpp.

351 {
352  S3D::ReadColor( aFile, ambient );
353  aFile.read( (char*) &shininess, sizeof( shininess ) );
354  aFile.read( (char*) &transparency, sizeof( transparency ) );
355  S3D::ReadColor( aFile, diffuse );
356  S3D::ReadColor( aFile, emissive );
357  S3D::ReadColor( aFile, specular );
358 
359  if( aFile.fail() )
360  return false;
361 
362  return true;
363 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
bool ReadColor(std::istream &aFile, SGCOLOR &aColor)
Definition: sg_helpers.cpp:295
SGCOLOR emissive
Definition: sg_appearance.h:78
SGCOLOR ambient
Definition: sg_appearance.h:76
float transparency
Definition: sg_appearance.h:75
SGCOLOR specular
Definition: sg_appearance.h:79

References ambient, diffuse, emissive, S3D::ReadColor(), shininess, specular, and transparency.

Referenced by SGSHAPE::ReadCache().

◆ ReNameNodes()

void SGAPPEARANCE::ReNameNodes ( void  )
overridevirtual

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

Implements SGNODE.

Definition at line 217 of file sg_appearance.cpp.

218 {
219  m_written = false;
220 
221  // rename this node
222  m_Name.clear();
223  GetName();
224 }
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 SGSHAPE::ReNameNodes().

◆ ResetNodeIndex()

void SGNODE::ResetNodeIndex ( void  )
noexceptinherited

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

Definition at line 238 of file sg_node.cpp.

239 {
240  for( int i = 0; i < (int)S3D::SGTYPE_END; ++i )
241  node_counts[i] = 1;
242 }
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().

◆ SetAmbient() [1/3]

bool SGAPPEARANCE::SetAmbient ( float  aRVal,
float  aGVal,
float  aBVal 
)

Definition at line 153 of file sg_appearance.cpp.

154 {
155  return ambient.SetColor( aRVal, aGVal, aBVal );
156 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR ambient
Definition: sg_appearance.h:76

References ambient, and SGCOLOR::SetColor().

◆ SetAmbient() [2/3]

bool SGAPPEARANCE::SetAmbient ( const SGCOLOR aRGBColor)

Definition at line 159 of file sg_appearance.cpp.

160 {
161  wxCHECK_MSG( aRGBColor, false, wxT( "NULL pointer passed for aRGBColor" ) );
162 
163  return ambient.SetColor( aRGBColor );
164 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR ambient
Definition: sg_appearance.h:76

References ambient, and SGCOLOR::SetColor().

◆ SetAmbient() [3/3]

bool SGAPPEARANCE::SetAmbient ( const SGCOLOR aRGBColor)

Definition at line 167 of file sg_appearance.cpp.

168 {
169  return ambient.SetColor( aRGBColor );
170 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR ambient
Definition: sg_appearance.h:76

References ambient, and SGCOLOR::SetColor().

◆ SetDiffuse() [1/3]

bool SGAPPEARANCE::SetDiffuse ( float  aRVal,
float  aGVal,
float  aBVal 
)

Definition at line 114 of file sg_appearance.cpp.

115 {
116  return diffuse.SetColor( aRVal, aGVal, aBVal );
117 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85

References diffuse, and SGCOLOR::SetColor().

◆ SetDiffuse() [2/3]

bool SGAPPEARANCE::SetDiffuse ( const SGCOLOR aRGBColor)

Definition at line 120 of file sg_appearance.cpp.

121 {
122  wxCHECK_MSG( aRGBColor, false, wxT( "NULL pointer passed for aRGBColor" ) );
123 
124  return diffuse.SetColor( aRGBColor );
125 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85

References diffuse, and SGCOLOR::SetColor().

◆ SetDiffuse() [3/3]

bool SGAPPEARANCE::SetDiffuse ( const SGCOLOR aRGBColor)

Definition at line 128 of file sg_appearance.cpp.

129 {
130  return diffuse.SetColor( aRGBColor );
131 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85

References diffuse, and SGCOLOR::SetColor().

◆ SetEmissive() [1/3]

bool SGAPPEARANCE::SetEmissive ( float  aRVal,
float  aGVal,
float  aBVal 
)

Definition at line 94 of file sg_appearance.cpp.

95 {
96  return emissive.SetColor( aRVal, aGVal, aBVal );
97 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR emissive
Definition: sg_appearance.h:78

References emissive, and SGCOLOR::SetColor().

◆ SetEmissive() [2/3]

bool SGAPPEARANCE::SetEmissive ( const SGCOLOR aRGBColor)

Definition at line 100 of file sg_appearance.cpp.

101 {
102  wxCHECK_MSG( aRGBColor, false, wxT( "NULL pointer passed for aRGBColor" ) );
103 
104  return emissive.SetColor( aRGBColor );
105 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR emissive
Definition: sg_appearance.h:78

References emissive, and SGCOLOR::SetColor().

◆ SetEmissive() [3/3]

bool SGAPPEARANCE::SetEmissive ( const SGCOLOR aRGBColor)

Definition at line 108 of file sg_appearance.cpp.

109 {
110  return emissive.SetColor( aRGBColor );
111 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR emissive
Definition: sg_appearance.h:78

References emissive, and SGCOLOR::SetColor().

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

◆ SetParent()

bool SGAPPEARANCE::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 64 of file sg_appearance.cpp.

65 {
66  if( nullptr != m_Parent )
67  {
68  if( aParent == m_Parent )
69  return true;
70 
71  // handle the change in parents
72  if( notify )
73  m_Parent->unlinkChildNode( this );
74 
75  m_Parent = nullptr;
76 
77  if( nullptr == aParent )
78  return true;
79  }
80 
81  // only a SGSHAPE may be parent to a SGAPPEARANCE
82  if( nullptr != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
83  return false;
84 
85  m_Parent = aParent;
86 
87  if( m_Parent )
88  m_Parent->AddChildNode( this );
89 
90  return true;
91 }
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_SHAPE, and SGNODE::unlinkChildNode().

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

◆ SetSpecular() [1/3]

bool SGAPPEARANCE::SetSpecular ( float  aRVal,
float  aGVal,
float  aBVal 
)

Definition at line 134 of file sg_appearance.cpp.

135 {
136  return specular.SetColor( aRVal, aGVal, aBVal );
137 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR specular
Definition: sg_appearance.h:79

References SGCOLOR::SetColor(), and specular.

◆ SetSpecular() [2/3]

bool SGAPPEARANCE::SetSpecular ( const SGCOLOR aRGBColor)

Definition at line 140 of file sg_appearance.cpp.

141 {
142  wxCHECK_MSG( aRGBColor, false, wxT( "NULL pointer passed for aRGBColor" ) );
143 
144  return specular.SetColor( aRGBColor );
145 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR specular
Definition: sg_appearance.h:79

References SGCOLOR::SetColor(), and specular.

◆ SetSpecular() [3/3]

bool SGAPPEARANCE::SetSpecular ( const SGCOLOR aRGBColor)

Definition at line 147 of file sg_appearance.cpp.

148 {
149  return specular.SetColor( aRGBColor );
150 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR specular
Definition: sg_appearance.h:79

References SGCOLOR::SetColor(), and specular.

◆ 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 SGAPPEARANCE::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 185 of file sg_appearance.cpp.

186 {
187  wxCHECK_MSG( aCaller, /* void */,
188  wxT( "unexpected code branch; node should have no children or refs" ) );
189 }

◆ unlinkRefNode()

void SGAPPEARANCE::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 192 of file sg_appearance.cpp.

193 {
194  wxCHECK_MSG( aCaller, /* void */,
195  wxT( "unexpected code branch; node should have no children or refs" ) );
196 }

◆ WriteCache()

bool SGAPPEARANCE::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 304 of file sg_appearance.cpp.

305 {
306  if( nullptr == parentNode )
307  {
308  wxCHECK_MSG( m_Parent, false, wxT( "corrupt data; m_aParent is NULL" ) );
309 
310  SGNODE* np = m_Parent;
311 
312  while( nullptr != np->GetParent() )
313  np = np->GetParent();
314 
315  if( np->WriteCache( aFile, nullptr ) )
316  {
317  m_written = true;
318  return true;
319  }
320 
321  return false;
322  }
323 
324  wxCHECK_MSG( parentNode == m_Parent, false, wxT( "corrupt data; parentNode != m_aParent" ) );
325 
326  if( !aFile.good() )
327  {
328  wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad stream" ),
329  __FILE__, __FUNCTION__, __LINE__ );
330 
331  return false;
332  }
333 
334  aFile << "[" << GetName() << "]";
335  S3D::WriteColor( aFile, ambient );
336  aFile.write( (char*) &shininess, sizeof( shininess ) );
337  aFile.write( (char*) &transparency, sizeof( transparency ) );
338  S3D::WriteColor( aFile, diffuse );
339  S3D::WriteColor( aFile, emissive );
340  S3D::WriteColor( aFile, specular );
341 
342  if( aFile.fail() )
343  return false;
344 
345  m_written = true;
346  return true;
347 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
bool WriteColor(std::ostream &aFile, const SGCOLOR &aColor)
Definition: sg_helpers.cpp:180
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
SGCOLOR emissive
Definition: sg_appearance.h:78
const char * GetName(void)
Definition: sg_node.cpp:146
SGCOLOR ambient
Definition: sg_appearance.h:76
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230
float transparency
Definition: sg_appearance.h:75
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.
SGCOLOR specular
Definition: sg_appearance.h:79

References ambient, diffuse, emissive, SGNODE::GetName(), SGNODE::GetParent(), SGNODE::m_Parent, SGNODE::m_written, shininess, specular, transparency, SGNODE::WriteCache(), and S3D::WriteColor().

Referenced by SGSHAPE::WriteCache().

◆ WriteVRML()

bool SGAPPEARANCE::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 227 of file sg_appearance.cpp.

228 {
229  if( aReuseFlag )
230  {
231  if( !m_written )
232  {
233  aFile << " appearance DEF " << GetName() << " Appearance {\n";
234  m_written = true;
235  }
236  else
237  {
238  aFile << " appearance USE " << GetName() << "\n";
239  return true;
240  }
241  }
242  else
243  {
244  aFile << " appearance Appearance {\n";
245  }
246 
247  aFile << " material Material {\n";
248 
249  std::string tmp;
250  float ambr, ambg, ambb;
251  ambient.GetColor( ambr, ambg, ambb );
252  float amb = ( 0.212671 * ambr + 0.71516 * ambg + 0.072169 * ambb );
253  diffuse.GetColor( ambr, ambg, ambb );
254  float den = ( 0.212671 * ambr + 0.71516 * ambg + 0.072169 * ambb );
255 
256  if( den < 0.004f )
257  den = 0.004f;
258 
259  amb /= den;
260 
261  if( amb > 1.0f )
262  amb = 1.0f;
263 
264  S3D::FormatFloat( tmp, amb );
265  aFile << " ambientIntensity " << tmp << "\n";
266 
267  float red, green, blue;
268  diffuse.GetColor( red, green, blue );
269  S3D::FormatFloat( tmp, red );
270  aFile << " diffuseColor " << tmp << " ";
271  S3D::FormatFloat( tmp, green );
272  aFile << tmp << " ";
273  S3D::FormatFloat( tmp, blue);
274  aFile << tmp << "\n";
275 
276  emissive.GetColor( red, green, blue );
277  S3D::FormatFloat( tmp, red );
278  aFile << " emissiveColor " << tmp << " ";
279  S3D::FormatFloat( tmp, green );
280  aFile << tmp << " ";
281  S3D::FormatFloat( tmp, blue);
282  aFile << tmp << "\n";
283 
284  S3D::FormatFloat( tmp, shininess );
285  aFile << " shininess " << tmp << "\n";
286 
287  specular.GetColor( red, green, blue );
288  S3D::FormatFloat( tmp, red );
289  aFile << " specularColor " << tmp << " ";
290  S3D::FormatFloat( tmp, green );
291  aFile << tmp << " ";
292  S3D::FormatFloat( tmp, blue);
293  aFile << tmp << "\n";
294 
296  aFile << " transparency " << tmp << "\n";
297 
298  aFile << "} }\n";
299 
300  return true;
301 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
SGCOLOR emissive
Definition: sg_appearance.h:78
void GetColor(float &aRedVal, float &aGreenVal, float &aBlueVal) const noexcept
Definition: sg_base.cpp:59
void FormatFloat(std::string &result, double value)
Definition: sg_helpers.cpp:37
const char * GetName(void)
Definition: sg_node.cpp:146
SGCOLOR ambient
Definition: sg_appearance.h:76
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230
float transparency
Definition: sg_appearance.h:75
SGCOLOR specular
Definition: sg_appearance.h:79

References ambient, diffuse, emissive, S3D::FormatFloat(), SGCOLOR::GetColor(), SGNODE::GetName(), SGNODE::m_written, red, shininess, specular, and transparency.

Referenced by SGSHAPE::WriteVRML().

Member Data Documentation

◆ ambient

SGCOLOR SGAPPEARANCE::ambient

◆ diffuse

SGCOLOR SGAPPEARANCE::diffuse

◆ emissive

SGCOLOR SGAPPEARANCE::emissive

Definition at line 78 of file sg_appearance.h.

Referenced by formatMaterial(), ReadCache(), SetEmissive(), WriteCache(), and WriteVRML().

◆ 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

◆ shininess

float SGAPPEARANCE::shininess

◆ specular

SGCOLOR SGAPPEARANCE::specular

◆ transparency

float SGAPPEARANCE::transparency

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