Go to the documentation of this file.
6 #ifndef CNOID_UTIL_SCENE_GRAPH_H
7 #define CNOID_UTIL_SCENE_GRAPH_H
9 #include <cnoid/ClonableReferenced>
10 #include <cnoid/SceneUpdate>
11 #include <cnoid/BoundingBox>
12 #include <cnoid/Signal>
17 #include "exportdecl.h"
36 return static_cast<SgObject*
>(doClone(
nullptr));
40 return static_cast<SgObject*
>(doClone(&cloneMap));
43 static bool checkNonNodeCloning(
const CloneMap& cloneMap);
44 static void setNonNodeCloning(
CloneMap& cloneMap,
bool on);
49 TransformNode = 1 << 2,
53 NodeDecoration = 1 << 6,
59 GroupAttribute = GroupNode,
60 NodeDecorationGroup = NodeDecoration,
61 MarkerAttribute = Marker
68 bool hasAttributes(
int attrs)
const {
return (attributes_ & attrs) == attrs; }
70 const std::string&
name()
const {
return name_; }
71 void setName(
const std::string& name) { name_ = name; }
73 virtual int numChildObjects()
const;
74 virtual SgObject* childObject(
int index);
82 notifyUpperNodesOfUpdate(update);
88 notifyUpperNodesOfUpdate(update);
93 int numParents()
const {
return static_cast<int>(parents.size()); }
104 return sigGraphConnection_;
111 bool hasUri()
const {
return uriInfo && !uriInfo->uri.empty(); }
112 const std::string& uri()
const;
114 const std::string& absoluteUri()
const;
116 const std::string& uriFragment()
const;
117 void setUriByFilePathAndBaseDirectory(
const std::string& filePath,
const std::string& baseDirectory);
118 void setUriByFilePathAndCurrentDirectory(
const std::string& filePath);
119 void setUri(
const std::string& uri,
const std::string& absoluteUri);
120 void setUriFragment(
const std::string& fragment);
123 bool isNode()
const {
return hasAttribute(Node); }
134 void notifyUpperNodesOfUpdate(
SgUpdate& update);
135 void notifyUpperNodesOfUpdate(
SgUpdate& update,
bool doInvalidateBoundingBox);
138 unsigned short attributes_;
139 mutable bool hasValidBoundingBoxCache_;
140 ParentContainer parents;
142 Signal<void(
bool on)> sigGraphConnection_;
147 std::string absoluteUri;
148 std::string fragment;
151 mutable std::unique_ptr<UriInfo> uriInfo;
165 static int findClassId(
const std::type_info& nodeType);
167 return findClassId(
typeid(NodeType));
171 return static_cast<SgNode*
>(this->clone());
174 return static_cast<SgNode*
>(this->clone(cloneMap));
178 virtual const BoundingBox& untransformedBoundingBox()
const;
183 template <
class NodeType,
class SuperType>
186 SgNode::registerNodeType(
typeid(NodeType),
typeid(SuperType));
192 return findClassId(
typeid(NodeType));
205 int decorationRefCounter;
208 static int registerNodeType(
const std::type_info& nodeType,
const std::type_info& superType);
222 typedef std::vector<SgNodePtr> Container;
234 virtual int numChildObjects()
const override;
235 virtual SgObject* childObject(
int index)
override;
236 virtual const BoundingBox& boundingBox()
const override;
252 bool empty()
const {
return children.empty(); }
253 int numChildren()
const {
return static_cast<int>(children.size()); }
256 bool contains(
SgNode* node)
const;
257 int findChildIndex(
SgNode* child)
const;
260 template<
class NodeType> NodeType*
getChild(
int index) {
261 NodeType* node =
dynamic_cast<NodeType*
>(children.at(index).get());
262 if(!node) throwTypeMismatchError();
271 iterator removeChild(iterator childIter,
SgUpdateRef update =
nullptr);
273 void removeChildAt(
int index,
SgUpdateRef update =
nullptr);
278 [[deprecated(
"Use insertChild(int index, SgNode* node, SgUpdateRef update)")]]
280 insertChild(index, node, update);
288 for(
int i=0; i < numChildren(); ++i){
289 if(NodeType* node =
dynamic_cast<NodeType*
>(child(i)))
return node;
291 if(depth < 0 || --depth > 0){
292 for(
int i=0; i < numChildren(); ++i){
293 auto child_ = child(i);
294 if(child_->isGroupNode()){
295 if(NodeType* node =
static_cast<SgGroup*
>(child_)->findNodeOfType<NodeType>(depth)){
311 static void throwTypeMismatchError();
339 virtual void getTransform(
Affine3& out_T)
const = 0;
340 virtual const BoundingBox& untransformedBoundingBox()
const override;
360 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
364 [[deprecated(
"Use SgPosTransform(const Isometry3& T)")]]
368 virtual const BoundingBox& boundingBox()
const override;
369 virtual void getTransform(
Affine3& out_T)
const override;
377 Isometry3::TranslationPart
translation() {
return T_.translation(); }
378 Isometry3::ConstTranslationPart
translation()
const {
return T_.translation(); }
380 Isometry3::LinearPart
rotation() {
return T_.linear(); }
381 Isometry3::ConstLinearPart
rotation()
const {
return T_.linear(); }
383 template<
class Scalar,
int Mode,
int Options>
384 void setPosition(
const Eigen::Transform<Scalar, 3, Mode, Options>& T) {
385 T_ = T.template cast<Isometry3::Scalar>();
387 template<
class Derived>
389 T_ = T.template cast<Isometry3::Scalar>();
391 template<
class Scalar,
int Mode,
int Options>
392 void setTransform(
const Eigen::Transform<Scalar, 3, Mode, Options>& T) {
393 T_ = T.template cast<Isometry3::Scalar>();
395 template<
typename Derived>
397 T_.linear() = R.template cast<Isometry3::Scalar>();
401 T_.linear() = aa.template cast<Isometry3::Scalar>().toRotationMatrix();
405 T_.linear() = q.template cast<Isometry3::Scalar>().toRotationMatrix();
407 template<
typename Derived>
409 T_.translation() = p.template cast<Isometry3::Scalar>();
430 virtual const BoundingBox& boundingBox()
const override;
431 virtual void getTransform(
Affine3& out_T)
const override;
435 template<
typename Derived>
436 void setScale(
const Eigen::MatrixBase<Derived>& s) {
437 scale_ = s.template cast<Vector3::Scalar>();
440 scale_.setConstant(s);
443 Eigen::DiagonalWrapper<const Vector3>
T()
const {
return scale_.asDiagonal(); }
459 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
465 virtual const BoundingBox& boundingBox()
const override;
466 virtual void getTransform(
Affine3& out_T)
const override;
474 template<
class Scalar,
int Mode,
int Options>
475 void setTransform(
const Eigen::Transform<Scalar, 3, Mode, Options>& T) {
476 T_ = T.template cast<Affine3::Scalar>();
479 Affine3::TranslationPart
translation() {
return T_.translation(); }
480 Affine3::ConstTranslationPart
translation()
const {
return T_.translation(); }
482 Affine3::LinearPart
linear() {
return T_.linear(); }
483 Affine3::ConstLinearPart
linear()
const {
return T_.linear(); }
485 template<
typename Derived>
487 T_.linear() = M.template cast<Affine3::Scalar>();
491 T_.linear() = aa.template cast<Affine3::Scalar>().toRotationMatrix();
493 template<
typename Derived>
495 T_.translation() = p.template cast<Affine3::Scalar>();
524 float pixelSizeRatio_;
536 void setTurnedOn(
bool on,
SgUpdateRef update =
nullptr);
557 void setSwitch(
SgSwitch* newSwitchObject);
559 void setTurnedOn(
bool on,
SgUpdateRef update =
nullptr);
562 return switchObject ? switchObject->
isTurnedOn() : isTurnedOn_;
565 [[deprecated(
"Use the setTurnedOn function.")]]
566 void turnOn(
bool doNotify =
false) { setTurnedOn(
true, doNotify); }
567 [[deprecated(
"Use the setTurnedOn function.")]]
568 void turnOff(
bool doNotify =
false) { setTurnedOn(
false, doNotify); }
ref_ptr< SgScaleTransform > SgScaleTransformPtr
Definition: SceneGraph.h:453
Definition: SceneDrawables.h:66
void setPosition(const Eigen::Transform< Scalar, 3, Mode, Options > &T)
Definition: SceneGraph.h:384
bool hasUri() const
Definition: SceneGraph.h:111
bool isDecoratedSomewhere() const
Definition: SceneGraph.h:197
Isometry3::ConstLinearPart rotation() const
Definition: SceneGraph.h:381
void setRotation(const Eigen::MatrixBase< Derived > &R)
Definition: SceneGraph.h:396
bool hasValidBoundingBoxCache() const
Definition: SceneGraph.h:107
void setRotation(const Eigen::Quaternion< T > &q)
Definition: SceneGraph.h:404
const_iterator cbegin()
Definition: SceneGraph.h:240
reverse_iterator rend()
Definition: SceneGraph.h:243
SgObject * clone(CloneMap &cloneMap) const
Definition: SceneGraph.h:39
SignalProxy< void(bool on)> sigGraphConnection()
Definition: SceneGraph.h:103
Definition: SceneGraph.h:357
void invalidateBoundingBox()
Definition: SceneGraph.h:108
Eigen::Vector3d Vector3
Definition: EigenTypes.h:57
void turnOff(bool doNotify=false)
Definition: SceneGraph.h:568
ParentContainer::const_iterator const_parentIter
Definition: SceneGraph.h:33
Definition: SceneCameras.h:56
Definition: SceneDrawables.h:337
ref_ptr< SgInvariantGroup > SgInvariantGroupPtr
Definition: SceneGraph.h:333
NodeType * getChild(int index)
This throws an exeption when the index is invalid or the type is not matched.
Definition: SceneGraph.h:260
NodeType * findNodeOfType(int depth=-1)
Definition: SceneGraph.h:287
Definition: SceneGraph.h:509
const_parentIter parentEnd() const
Definition: SceneGraph.h:97
SgNode * cloneNode() const
Definition: SceneGraph.h:170
void reservePathCapacity(int n)
Definition: SceneUpdate.h:37
ref_ptr< SgTransform > SgTransformPtr
Definition: SceneGraph.h:348
Definition: SceneDrawables.h:570
Isometry3 & T()
Definition: SceneGraph.h:371
Definition: SceneGraph.h:220
SgTransform * toTransformNode()
Definition: SceneGraph.h:351
reverse_iterator rbegin()
Definition: SceneGraph.h:242
Definition: SceneGraph.h:549
Eigen::Isometry3d Isometry3
Definition: EigenTypes.h:73
Container::const_iterator const_iterator
Definition: SceneGraph.h:227
Definition: SceneDrawables.h:660
void setTransform(const Eigen::Transform< Scalar, 3, Mode, Options > &T)
Definition: SceneGraph.h:392
Definition: SceneCameras.h:14
Isometry3::ConstTranslationPart translation() const
Definition: SceneGraph.h:378
static int findPolymorphicId()
Definition: SceneGraph.h:191
Attribute
Definition: SceneGraph.h:46
int attributes() const
Definition: SceneGraph.h:66
void setRotation(const Eigen::AngleAxis< T > &aa)
Definition: SceneGraph.h:400
void notifyUpdate(int action=SgUpdate::Modified)
Definition: SceneGraph.h:85
Definition: SceneGraph.h:595
Definition: SceneLights.h:90
SgObject * clone() const
Definition: SceneGraph.h:35
void addDecorationReference()
Definition: SceneGraph.h:195
ref_ptr< SgPreprocessed > SgPreprocessedPtr
Definition: SceneGraph.h:602
Definition: SceneLights.h:14
SgGroup * toGroupNode()
Definition: SceneGraph.h:317
std::set< SgObject * > ParentContainer
Definition: SceneGraph.h:31
Container::const_reverse_iterator const_reverse_iterator
Definition: SceneGraph.h:228
Definition: SceneUpdate.h:10
BoundingBox bboxCache
Definition: SceneGraph.h:307
const Isometry3 & position() const
Definition: SceneGraph.h:375
Definition: SceneUpdate.h:73
Container::reverse_iterator reverse_iterator
Definition: SceneGraph.h:226
int classId() const
Definition: SceneGraph.h:164
const_parentIter parentBegin() const
Definition: SceneGraph.h:96
Definition: SceneGraph.h:581
Definition: Referenced.h:103
bool hasParents() const
Definition: SceneGraph.h:94
void insertChild(SgNode *node, int index, SgUpdateRef update=nullptr)
Definition: SceneGraph.h:279
registerType()
Definition: SceneGraph.h:185
void setPixelSizeRatio(float ratio)
Definition: SceneGraph.h:516
void releaseDecorationReference()
Definition: SceneGraph.h:196
void setName(const std::string &name)
Definition: SceneGraph.h:71
const_iterator cend()
Definition: SceneGraph.h:241
iterator end()
Definition: SceneGraph.h:239
Definition: SceneGraph.h:323
Definition: SceneDrawables.h:737
void setTranslation(const Eigen::MatrixBase< Derived > &p)
Definition: SceneGraph.h:408
Definition: SceneEffects.h:149
iterator erase(iterator pos)
Definition: SceneGraph.h:250
bool isTransformNode() const
Definition: SceneGraph.h:127
bool isNode() const
Definition: SceneGraph.h:123
Definition: SceneEffects.h:69
const SgNode * child(int index) const
Definition: SceneGraph.h:255
Isometry3::TranslationPart translation()
Definition: SceneGraph.h:377
Definition: SceneDrawables.h:503
Definition: AbstractSceneLoader.h:11
ref_ptr< SgPosTransform > SgPosTransformPtr
Definition: SceneGraph.h:420
Definition: SceneLights.h:43
ref_ptr< SgNode > SgNodePtr
Definition: SceneGraph.h:211
const std::string & name() const
Definition: SceneGraph.h:70
Definition: ClonableReferenced.h:10
Isometry3 & position()
Definition: SceneGraph.h:374
Definition: CloneMap.h:13
int numParents() const
Definition: SceneGraph.h:93
Definition: SceneDrawables.h:101
void setPosition(const Eigen::MatrixBase< Derived > &T)
Definition: SceneGraph.h:388
Definition: SceneEffects.h:173
Definition: SceneDrawables.h:636
SgNode * cloneNode(CloneMap &cloneMap) const
Definition: SceneGraph.h:173
void notifyUpdate(SgUpdate &update)
Definition: SceneGraph.h:80
ref_ptr< SgUnpickableGroup > SgUnpickableGroupPtr
Definition: SceneGraph.h:592
bool empty() const
Definition: SceneGraph.h:252
ref_ptr< SgObject > SgObjectPtr
Definition: SceneGraph.h:154
void clearPath()
Definition: SceneUpdate.h:46
void turnOn(bool doNotify=false)
Definition: SceneGraph.h:566
void setAttribute(int attr)
Definition: SceneGraph.h:64
iterator begin()
Definition: SceneGraph.h:238
float pixelSizeRatio() const
Definition: SceneGraph.h:517
bool isTurnedOn() const
Definition: SceneGraph.h:561
ref_ptr< SgAffineTransform > SgAffineTransformPtr
Definition: SceneGraph.h:506
static int findClassId()
Definition: SceneGraph.h:166
const_iterator end() const
Definition: SceneGraph.h:246
Definition: SceneGraph.h:530
Definition: Referenced.h:54
Container::iterator iterator
Definition: SceneGraph.h:225
Definition: SceneGraph.h:184
int numChildren() const
Definition: SceneGraph.h:253
SignalProxy< void(const SgUpdate &update)> sigUpdated()
Definition: SceneGraph.h:76
@ Modified
Definition: SceneUpdate.h:19
void setBoundingBoxCacheReady() const
Definition: SceneGraph.h:109
const Isometry3 & T() const
Definition: SceneGraph.h:372
std::vector< SgNode * > SgNodePath
Definition: SceneGraph.h:24
Definition: SceneDrawables.h:530
SgNode * toNode()
Definition: SceneGraph.h:214
SgNode * child(int index)
Definition: SceneGraph.h:254
Isometry3::LinearPart rotation()
Definition: SceneGraph.h:380
const_reverse_iterator rbegin() const
Definition: SceneGraph.h:247
ref_ptr< SgSwitchableGroup > SgSwitchableGroupPtr
Definition: SceneGraph.h:578
Definition: SceneGraph.h:28
ref_ptr< SgGroup > SgGroupPtr
Definition: SceneGraph.h:314
void setAttributes(int attrs)
Definition: SceneGraph.h:65
bool hasAttributes(int attrs) const
Definition: SceneGraph.h:68
ref_ptr< SgSwitch > SgSwitchPtr
Definition: SceneGraph.h:546
ParentContainer::iterator parentIter
Definition: SceneGraph.h:32
Definition: SceneDrawables.h:752
Definition: SceneDrawables.h:18
Definition: SceneGraph.h:157
ref_ptr< SgFixedPixelSizeGroup > SgFixedPixelSizeGroupPtr
Definition: SceneGraph.h:527
Definition: SceneCameras.h:83
void clearUri()
Definition: SceneGraph.h:121
Eigen::Affine3d Affine3
Definition: EigenTypes.h:62
Definition: BoundingBox.h:17
Definition: SceneLights.h:63
bool hasUriFragment() const
Definition: SceneGraph.h:115
const_reverse_iterator rend() const
Definition: SceneGraph.h:248
bool isGroupNode() const
Definition: SceneGraph.h:125
Definition: SceneDrawables.h:134
bool hasAttribute(int attr) const
Definition: SceneGraph.h:67
bool isTurnedOn() const
Definition: SceneGraph.h:537
bool hasAbsoluteUri() const
Definition: SceneGraph.h:113
const_iterator begin() const
Definition: SceneGraph.h:245