MeshLib C++ Docs
Loading...
Searching...
No Matches

named object in the data model More...

#include <MRMesh/MRObject.h>

Inheritance diagram for MR::Object:

Classes

struct  ProtectedStruct

Public Types

using XfChangedSignal = Signal<void()>

Public Member Functions

 Object ()=default
 Object (Object &&) noexcept=default
Objectoperator= (Object &&) noexcept=default
virtual ~Object ()=default
virtual const char * typeName () const
virtual std::string className () const
virtual std::string classNameInPlural () const
template<typename T>
T * asType ()
template<typename T>
const T * asType () const
const std::string & name () const
virtual void setName (std::string name)
std::shared_ptr< const Objectfind (const std::string_view &name) const
 finds a direct child by name
std::shared_ptr< Objectfind (const std::string_view &name)
template<typename T>
std::shared_ptr< const T > find () const
 finds a direct child by type
template<typename T>
std::shared_ptr< T > find ()
template<typename T>
std::shared_ptr< const T > find (const std::string_view &name) const
 finds a direct child by name and type
template<typename T>
std::shared_ptr< T > find (const std::string_view &name)
const AffineXf3f & xf (ViewportId id={}, bool *isDef=nullptr) const
virtual void setXf (const AffineXf3f &xf, ViewportId id={})
virtual void resetXf (ViewportId id={})
 forgets specific transform in given viewport (or forgets all specific transforms for {} input)
const ViewportProperty< AffineXf3f > & xfsForAllViewports () const
 returns xfs for all viewports, combined into a single object
virtual void setXfsForAllViewports (ViewportProperty< AffineXf3f > xf)
 modifies xfs for all viewports at once
AffineXf3f worldXf (ViewportId id={}, bool *isDef=nullptr) const
void setWorldXf (const AffineXf3f &xf, ViewportId id={})
virtual void applyScale (float scaleFactor)
 scale object size (all point positions)
ViewportMask globalVisibilityMask () const
 returns all viewports where this object is visible together with all its parents
bool globalVisibility (ViewportMask viewportMask=ViewportMask::any()) const
 returns true if this object is visible together with all its parents in any of given viewports
void setGlobalVisibility (bool on, ViewportMask viewportMask=ViewportMask::any())
 if true sets all predecessors visible, otherwise sets this object invisible
bool isLocked () const
 object properties lock for UI
virtual void setLocked (bool on)
bool isParentLocked () const
virtual void setParentLocked (bool lock)
const Objectparent () const
 returns parent object in the tree
Objectparent ()
bool isAncestor (const Object *ancestor) const
 return true if given object is ancestor of this one, false otherwise
ObjectfindCommonAncestor (Object &other)
const ObjectfindCommonAncestor (const Object &other) const
virtual bool detachFromParent ()
const std::vector< std::shared_ptr< Object > > & children ()
 an object can hold other sub-objects
const std::vector< std::shared_ptr< const Object > > & children () const
virtual bool addChild (std::shared_ptr< Object > child, bool recognizedChild=true)
virtual bool addChildBefore (std::shared_ptr< Object > newChild, const std::shared_ptr< Object > &existingChild)
bool removeChild (const std::shared_ptr< Object > &child)
 returns false if it was not child of this
virtual bool removeChild (Object *child)
virtual void removeAllChildren ()
 detaches all recognized children from this, keeping all unrecognized ones
void sortChildren ()
 sort recognized children by name
virtual bool select (bool on)
 selects the object, returns true if value changed, otherwise returns false
virtual bool isSelected () const
virtual void setAncillary (bool ancillary)
bool isAncillary () const
bool isGlobalAncillary () const
 returns true if the object or any of its ancestors are ancillary
void setVisible (bool on, ViewportMask viewportMask=ViewportMask::all())
 sets the object visible in the viewports specified by the mask (by default in all viewports)
bool isVisible (ViewportMask viewportMask=ViewportMask::any()) const
 checks whether the object is visible in any of the viewports specified by the mask (by default in any viewport)
virtual void setVisibilityMask (ViewportMask viewportMask)
 specifies object visibility as bitmask of viewports
virtual ViewportMask visibilityMask () const
 gets object visibility as bitmask of viewports
virtual bool getRedrawFlag (ViewportMask) const
 this method virtual because others data model types could have dirty flags or something
void resetRedrawFlag () const
std::shared_ptr< ObjectcloneTree () const
 clones all tree of this object (except ancillary and unrecognized children)
virtual std::shared_ptr< Objectclone () const
 clones current object only, without parent and/or children
std::shared_ptr< ObjectshallowCloneTree () const
virtual std::shared_ptr< ObjectshallowClone () const
virtual std::vector< std::string > getInfoLines () const
 return several info lines that can better describe object in the UI
MR_BIND_IGNORE Expected< std::vector< std::future< Expected< void > > > > serializeRecursive (const std::filesystem::path &path, Json::Value &root, int childId) const
Expected< void > deserializeRecursive (const std::filesystem::path &path, const Json::Value &root, ProgressCallback progressCb={}, int *objCounter=nullptr)
void swap (Object &other)
virtual Box3f getWorldBox (ViewportId={}) const
 returns bounding box of this object in world coordinates for default or specific viewport
Box3f getWorldTreeBox (ViewportId={}) const
 returns bounding box of this object and all children visible in given (or default) viewport in world coordinates
virtual bool hasVisualRepresentation () const
 does the object have any visual representation (visible points, triangles, edges, etc.), no considering child objects
virtual bool hasModel () const
const std::set< std::string > & tags () const
bool addTag (std::string tag)
bool removeTag (const std::string &tag)
virtual size_t heapBytes () const
 returns the amount of memory this object occupies on heap
virtual bool sameModels (const Object &other) const
 return true if model of current object equals to model (the same) of other
virtual size_t getModelHash () const
 return hash of model (or hash object pointer if object has no model)
 Object (ProtectedStruct, const Object &obj)
Public Member Functions inherited from MR::ObjectChildrenHolder
 ObjectChildrenHolder ()=default
 ObjectChildrenHolder (const ObjectChildrenHolder &) noexcept
ObjectChildrenHolderoperator= (const ObjectChildrenHolder &) noexcept
 ObjectChildrenHolder (ObjectChildrenHolder &&) noexcept
ObjectChildrenHolderoperator= (ObjectChildrenHolder &&) noexcept
 ~ObjectChildrenHolder ()
std::shared_ptr< ObjectgetSharedPtr () const
size_t heapBytes () const

Static Public Member Functions

static constexpr const char * StaticTypeName () noexcept
 return name of subtype for serialization purposes
static constexpr const char * StaticClassName () noexcept
 return human readable name of subclass
static constexpr const char * StaticClassNameInPlural () noexcept
 return human readable name of subclass in plural form

Public Attributes

XfChangedSignal worldXfChangedSignal

Protected Member Functions

 Object (const Object &obj)=default
 user should not be able to call copy implicitly, use clone() function instead
virtual void swapBase_ (Object &other)
 swaps whole object (signals too)
virtual void swapSignals_ (Object &other)
virtual Expected< std::future< Expected< void > > > serializeModel_ (const std::filesystem::path &path) const
virtual void serializeFields_ (Json::Value &root) const
virtual Expected< void > deserializeModel_ (const std::filesystem::path &path, ProgressCallback progressCb={})
 Reads model from file.
virtual Expected< void > setSharedModel_ (const Object &other)
 shares model from other object
virtual void deserializeFields_ (const Json::Value &root)
void sendWorldXfChangedSignal_ ()
virtual void onWorldXfChanged_ ()
 Emits worldXfChangedSignal, but derived classes can add additional behavior to it.

Protected Attributes

std::string name_
ViewportProperty< AffineXf3f > xf_
ViewportMask visibilityMask_ = ViewportMask::all()
bool locked_ = false
 Prefer to not read directly. Use the getter, as it can be overridden.
bool parentLocked_ = false
bool selected_ { false }
bool ancillary_ { false }
bool needRedraw_ {false}
std::set< std::string > tags_
Protected Attributes inherited from MR::ObjectChildrenHolder
ObjectChildrenHolderparent_ = nullptr
std::vector< std::shared_ptr< Object > > children_
std::vector< std::weak_ptr< Object > > bastards_
 recognized ones

Detailed Description

named object in the data model

Member Typedef Documentation

◆ XfChangedSignal

signal about xf changing triggered in setXf and setWorldXf, it is called for children too triggered in addChild and addChildBefore, it is called only for children object

Constructor & Destructor Documentation

◆ Object() [1/4]

MR::Object::Object ( )
default

◆ Object() [2/4]

MR::Object::Object ( Object && )
defaultnoexcept

◆ ~Object()

virtual MR::Object::~Object ( )
virtualdefault

◆ Object() [3/4]

MR::Object::Object ( ProtectedStruct ,
const Object & obj )
inline
Note
this ctor is public only for std::make_shared used inside clone()

◆ Object() [4/4]

MR::Object::Object ( const Object & obj)
protecteddefault

user should not be able to call copy implicitly, use clone() function instead

Member Function Documentation

◆ addChild()

virtual bool MR::Object::addChild ( std::shared_ptr< Object > child,
bool recognizedChild = true )
virtual

adds given object at the end of children (recognized or not); returns false if it was already child of this, of if given pointer is empty; child object will always report this as parent after the call;

Parameters
recognizedChildif set to false then child object will be excluded from children() and it will be stored by weak_ptr

◆ addChildBefore()

virtual bool MR::Object::addChildBefore ( std::shared_ptr< Object > newChild,
const std::shared_ptr< Object > & existingChild )
virtual

adds given object in the recognized children before existingChild; if newChild was already among this children then moves it just before existingChild keeping the order of other children intact; returns false if newChild is nullptr, or existingChild is not a child of this

◆ addTag()

bool MR::Object::addTag ( std::string tag)

adds tag to the object's tag storage additionally calls ObjectTagManager::tagAddedSignal NOTE: tags starting with a dot are considered as service ones and might be hidden from UI

◆ applyScale()

virtual void MR::Object::applyScale ( float scaleFactor)
virtual

◆ asType() [1/2]

template<typename T>
T * MR::Object::asType ( )
inline

◆ asType() [2/2]

template<typename T>
const T * MR::Object::asType ( ) const
inline

◆ children() [1/2]

const std::vector< std::shared_ptr< Object > > & MR::Object::children ( )
inline

an object can hold other sub-objects

◆ children() [2/2]

const std::vector< std::shared_ptr< const Object > > & MR::Object::children ( ) const
inline

◆ className()

◆ classNameInPlural()

◆ clone()

◆ cloneTree()

std::shared_ptr< Object > MR::Object::cloneTree ( ) const

clones all tree of this object (except ancillary and unrecognized children)

◆ deserializeFields_()

virtual void MR::Object::deserializeFields_ ( const Json::Value & root)
protectedvirtual

◆ deserializeModel_()

virtual Expected< void > MR::Object::deserializeModel_ ( const std::filesystem::path & path,
ProgressCallback progressCb = {} )
protectedvirtual

◆ deserializeRecursive()

Expected< void > MR::Object::deserializeRecursive ( const std::filesystem::path & path,
const Json::Value & root,
ProgressCallback progressCb = {},
int * objCounter = nullptr )

loads subtree into this Object models from the folder by given path and fields from given JSON

◆ detachFromParent()

virtual bool MR::Object::detachFromParent ( )
virtual

removes this from its parent children list returns false if it was already orphan

◆ find() [1/4]

template<typename T>
std::shared_ptr< T > MR::Object::find ( )
inline

◆ find() [2/4]

std::shared_ptr< Object > MR::Object::find ( const std::string_view & name)
inline

◆ find() [3/4]

template<typename T>
std::shared_ptr< T > MR::Object::find ( const std::string_view & name)
inline

◆ find() [4/4]

std::shared_ptr< const Object > MR::Object::find ( const std::string_view & name) const

finds a direct child by name

◆ findCommonAncestor() [1/2]

const Object * MR::Object::findCommonAncestor ( const Object & other) const
inlinenodiscard

◆ findCommonAncestor() [2/2]

Object * MR::Object::findCommonAncestor ( Object & other)
nodiscard

Find a common ancestor between this object and the other one. Returns null on failure (which is impossible if both are children of the scene root). Will return this if other matches this.

◆ getInfoLines()

virtual std::vector< std::string > MR::Object::getInfoLines ( ) const
virtual

◆ getModelHash()

virtual size_t MR::Object::getModelHash ( ) const
virtual

return hash of model (or hash object pointer if object has no model)

Reimplemented in MR::ObjectMeshHolder.

◆ getRedrawFlag()

virtual bool MR::Object::getRedrawFlag ( ViewportMask ) const
inlinevirtual

this method virtual because others data model types could have dirty flags or something

Reimplemented in MR::ObjectMeshHolder, and MR::VisualObject.

◆ getWorldBox()

virtual Box3f MR::Object::getWorldBox ( ViewportId = {}) const
inlinevirtual

returns bounding box of this object in world coordinates for default or specific viewport

Reimplemented in MR::ObjectLabel, MR::ObjectLinesHolder, MR::ObjectMeshHolder, MR::ObjectPointsHolder, and MR::VisualObject.

◆ getWorldTreeBox()

Box3f MR::Object::getWorldTreeBox ( ViewportId = {}) const

returns bounding box of this object and all children visible in given (or default) viewport in world coordinates

empty box

◆ globalVisibility()

bool MR::Object::globalVisibility ( ViewportMask viewportMask = ViewportMask::any()) const
inline

returns true if this object is visible together with all its parents in any of given viewports

◆ globalVisibilityMask()

ViewportMask MR::Object::globalVisibilityMask ( ) const

returns all viewports where this object is visible together with all its parents

◆ hasModel()

virtual bool MR::Object::hasModel ( ) const
inlinenodiscardvirtual

does the object have any model available (but possibly empty), e.g. ObjectMesh has valid mesh() or ObjectPoints has valid pointCloud()

Reimplemented in MR::ObjectDistanceMap, MR::ObjectLinesHolder, MR::ObjectMeshHolder, MR::ObjectPointsHolder, and MR::ObjectVoxels.

◆ hasVisualRepresentation()

virtual bool MR::Object::hasVisualRepresentation ( ) const
inlinenodiscardvirtual

does the object have any visual representation (visible points, triangles, edges, etc.), no considering child objects

Reimplemented in MR::ObjectImGuiLabel, MR::ObjectLabel, MR::ObjectLinesHolder, MR::ObjectMeshHolder, MR::ObjectPointsHolder, and MR::ObjectVoxels.

◆ heapBytes()

virtual size_t MR::Object::heapBytes ( ) const
nodiscardvirtual

◆ isAncestor()

bool MR::Object::isAncestor ( const Object * ancestor) const

return true if given object is ancestor of this one, false otherwise

◆ isAncillary()

bool MR::Object::isAncillary ( ) const
inline

◆ isGlobalAncillary()

bool MR::Object::isGlobalAncillary ( ) const

returns true if the object or any of its ancestors are ancillary

◆ isLocked()

bool MR::Object::isLocked ( ) const
inline

object properties lock for UI

◆ isParentLocked()

bool MR::Object::isParentLocked ( ) const
inlinenodiscard

If true, the scene tree GUI doesn't allow you to drag'n'drop this object into a different parent. Defaults to false.

◆ isSelected()

virtual bool MR::Object::isSelected ( ) const
inlinevirtual

◆ isVisible()

bool MR::Object::isVisible ( ViewportMask viewportMask = ViewportMask::any()) const
inline

checks whether the object is visible in any of the viewports specified by the mask (by default in any viewport)

◆ name()

const std::string & MR::Object::name ( ) const
inline

◆ onWorldXfChanged_()

virtual void MR::Object::onWorldXfChanged_ ( )
protectedvirtual

Emits worldXfChangedSignal, but derived classes can add additional behavior to it.

Reimplemented in MR::AngleMeasurementObject, MR::DistanceMeasurementObject, and MR::RadiusMeasurementObject.

◆ operator=()

Object & MR::Object::operator= ( Object && )
defaultnoexcept

◆ parent() [1/2]

Object * MR::Object::parent ( )
inline

◆ parent() [2/2]

const Object * MR::Object::parent ( ) const
inline

returns parent object in the tree

◆ removeAllChildren()

virtual void MR::Object::removeAllChildren ( )
virtual

detaches all recognized children from this, keeping all unrecognized ones

◆ removeChild() [1/2]

bool MR::Object::removeChild ( const std::shared_ptr< Object > & child)
inline

returns false if it was not child of this

◆ removeChild() [2/2]

virtual bool MR::Object::removeChild ( Object * child)
virtual

◆ removeTag()

bool MR::Object::removeTag ( const std::string & tag)

removes tag from the object's tag storage additionally calls ObjectTagManager::tagRemovedSignal

◆ resetRedrawFlag()

void MR::Object::resetRedrawFlag ( ) const
inline

◆ resetXf()

virtual void MR::Object::resetXf ( ViewportId id = {})
virtual

forgets specific transform in given viewport (or forgets all specific transforms for {} input)

Reimplemented in MR::FeatureObject.

◆ sameModels()

virtual bool MR::Object::sameModels ( const Object & other) const
virtual

return true if model of current object equals to model (the same) of other

Reimplemented in MR::ObjectMeshHolder.

◆ select()

virtual bool MR::Object::select ( bool on)
virtual

selects the object, returns true if value changed, otherwise returns false

Reimplemented in MR::ObjectGcode, and MR::SceneRootObject.

◆ sendWorldXfChangedSignal_()

void MR::Object::sendWorldXfChangedSignal_ ( )
protected

This calls onWorldXfChanged_() for all children recursively, which in turn emits worldXfChangedSignal. This isn't virtual because it wouldn't be very useful, because it doesn't call itself on the children (it doesn't use a true recursion, instead imitating one, presumably to save stack space, though this is unlikely to be an issue).

◆ serializeFields_()

◆ serializeModel_()

virtual Expected< std::future< Expected< void > > > MR::Object::serializeModel_ ( const std::filesystem::path & path) const
protectedvirtual

Creates future to save object model (e.g. mesh) in given file path is full filename without extension

Reimplemented in MR::CircleObject, MR::ConeObject, MR::CylinderObject, MR::LineObject, MR::ObjectDistanceMap, MR::ObjectMeshHolder, MR::ObjectPointsHolder, MR::ObjectVoxels, MR::PlaneObject, MR::PointObject, and MR::SphereObject.

◆ serializeRecursive()

MR_BIND_IGNORE Expected< std::vector< std::future< Expected< void > > > > MR::Object::serializeRecursive ( const std::filesystem::path & path,
Json::Value & root,
int childId ) const

creates futures that save this object subtree: models in the folder by given path and fields in given JSON

Parameters
childIdis its ordinal number within the parent This would be automatically skipped in the bindings anyway because of the Json::Value parameter. But skipping it here prevents the vector-of-futures type from being registered, which is helpful. TODO: figure out how to automate this (add a flag to the parser to outright reject functions based on their parameter and return types).

◆ setAncillary()

virtual void MR::Object::setAncillary ( bool ancillary)
virtual

ancillary object is an object hidden (in scene menu) from a regular user such objects cannot be selected, and if it has been selected, it is unselected when turn ancillary

Reimplemented in MR::SceneRootObject.

◆ setGlobalVisibility()

void MR::Object::setGlobalVisibility ( bool on,
ViewportMask viewportMask = ViewportMask::any() )

if true sets all predecessors visible, otherwise sets this object invisible

◆ setLocked()

virtual void MR::Object::setLocked ( bool on)
inlinevirtual

◆ setName()

virtual void MR::Object::setName ( std::string name)
inlinevirtual

Reimplemented in MR::SceneRootObject.

◆ setParentLocked()

virtual void MR::Object::setParentLocked ( bool lock)
inlinevirtual

◆ setSharedModel_()

virtual Expected< void > MR::Object::setSharedModel_ ( const Object & other)
protectedvirtual

shares model from other object

Reimplemented in MR::ObjectMeshHolder.

◆ setVisibilityMask()

virtual void MR::Object::setVisibilityMask ( ViewportMask viewportMask)
virtual

specifies object visibility as bitmask of viewports

◆ setVisible()

void MR::Object::setVisible ( bool on,
ViewportMask viewportMask = ViewportMask::all() )

sets the object visible in the viewports specified by the mask (by default in all viewports)

◆ setWorldXf()

void MR::Object::setWorldXf ( const AffineXf3f & xf,
ViewportId id = {} )

◆ setXf()

virtual void MR::Object::setXf ( const AffineXf3f & xf,
ViewportId id = {} )
virtual

Reimplemented in MR::FeatureObject.

◆ setXfsForAllViewports()

virtual void MR::Object::setXfsForAllViewports ( ViewportProperty< AffineXf3f > xf)
inlinevirtual

modifies xfs for all viewports at once

◆ shallowClone()

◆ shallowCloneTree()

std::shared_ptr< Object > MR::Object::shallowCloneTree ( ) const

clones all tree of this object (except ancillary and unrecognied children) clones only pointers to mesh, points or voxels

◆ sortChildren()

void MR::Object::sortChildren ( )

sort recognized children by name

◆ StaticClassName()

constexpr const char * MR::Object::StaticClassName ( )
inlinestaticconstexprnoexcept

return human readable name of subclass

◆ StaticClassNameInPlural()

constexpr const char * MR::Object::StaticClassNameInPlural ( )
inlinestaticconstexprnoexcept

return human readable name of subclass in plural form

◆ StaticTypeName()

constexpr const char * MR::Object::StaticTypeName ( )
inlinestaticconstexprnoexcept

return name of subtype for serialization purposes

◆ swap()

void MR::Object::swap ( Object & other)

swaps this object with other note: do not swap object signals, so listeners will get notifications from swapped object requires implementation of swapBase_ and swapSignals_ (if type has signals)

◆ swapBase_()

◆ swapSignals_()

virtual void MR::Object::swapSignals_ ( Object & other)
protectedvirtual

swaps signals, used in swap function to return back signals after swapBase_

Note
pls call Parent::swapSignals_ first when overriding this function

Reimplemented in MR::ObjectGcode, MR::ObjectLinesHolder, MR::ObjectMeshHolder, MR::ObjectPointsHolder, and MR::ObjectVoxels.

◆ tags()

const std::set< std::string > & MR::Object::tags ( ) const
inline

provides read-only access to the tag storage the storage is a set of unique strings

◆ typeName()

◆ visibilityMask()

virtual ViewportMask MR::Object::visibilityMask ( ) const
inlinevirtual

gets object visibility as bitmask of viewports

◆ worldXf()

AffineXf3f MR::Object::worldXf ( ViewportId id = {},
bool * isDef = nullptr ) const

this space to world space transformation for default or specific viewport

Parameters
isDefreceives true if the object has default transformation in this viewport (same as worldXf() returns)

◆ xf()

const AffineXf3f & MR::Object::xf ( ViewportId id = {},
bool * isDef = nullptr ) const
inline

this space to parent space transformation (to world space if no parent) for default or given viewport

Parameters
isDefreceives true if the object has default transformation in this viewport (same as xf() returns)

◆ xfsForAllViewports()

const ViewportProperty< AffineXf3f > & MR::Object::xfsForAllViewports ( ) const
inline

returns xfs for all viewports, combined into a single object

Member Data Documentation

◆ ancillary_

bool MR::Object::ancillary_ { false }
protected

◆ locked_

bool MR::Object::locked_ = false
protected

Prefer to not read directly. Use the getter, as it can be overridden.

◆ name_

std::string MR::Object::name_
protected

◆ needRedraw_

bool MR::Object::needRedraw_ {false}
mutableprotected

◆ parentLocked_

bool MR::Object::parentLocked_ = false
protected

◆ selected_

bool MR::Object::selected_ { false }
protected

◆ tags_

std::set<std::string> MR::Object::tags_
protected

◆ visibilityMask_

ViewportMask MR::Object::visibilityMask_ = ViewportMask::all()
protected

◆ worldXfChangedSignal

XfChangedSignal MR::Object::worldXfChangedSignal

◆ xf_

ViewportProperty<AffineXf3f> MR::Object::xf_
protected

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