Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scripts/mrbind/aliases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ static const char MRBIND_UNIQUE_VAR = []
MR_ALIAS( MeshBuilderSettings, MeshBuilder.BuildSettings );
MR_ALIAS( MeshToVolumeParamsType, MeshToVolumeParams.Type );
MR_ALIAS( ObjectDistanceMap.extractDistanceMap, ObjectDistanceMap.getDistanceMap );
MR_ALIAS( ObjectLines.extractLines, ObjectLines.polyline );
MR_ALIAS( ObjectMesh.extractMesh, ObjectMesh.mesh );
MR_ALIAS( ObjectPoints.extractPoints, ObjectPoints.pointCloud );
MR_ALIAS( ObjectLines.extractLines, ObjectLines.polylinePtr );
MR_ALIAS( ObjectMesh.extractMesh, ObjectMesh.meshPtr );
MR_ALIAS( ObjectPoints.extractPoints, ObjectPoints.pointCloudPtr );
MR_ALIAS( objectSave, ObjectSave.toAnySupportedFormat );
MR_ALIAS( ObjectVoxels.extractVoxels, ObjectVoxels.vdbVolume );
MR_ALIAS( saveAllSlicesToImage, VoxelsSave.saveAllSlicesToImage );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ bool SaveSelectedMenuItem::action()
{
std::vector<MeshSave::NamedXfMesh> objs;
for ( auto obj : selectedMeshes )
objs.push_back( MeshSave::NamedXfMesh{ obj->name(),obj->worldXf(),obj->mesh() } );
objs.push_back( MeshSave::NamedXfMesh{ obj->name(),obj->worldXf(),obj->varMesh() } );

ProgressBar::orderWithMainThreadPostProcessing( "Saving selected", [savePath, objs] ()->std::function<void()>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ std::string FitSelectedPrimitivesMenuItem::isAvailable( const std::vector<std::s
{
auto allObjs = getAllObjectsInTree<ObjectMesh>( &SceneRoot::get(), ObjectSelectivityType::Any );
for ( const auto& obj : allObjs )
if ( obj->globalVisibility() && obj->mesh() && ( obj->getSelectedEdges().any() || obj->getSelectedFaces().any() ) )
if ( obj->globalVisibility() && obj->meshPtr() && ( obj->getSelectedEdges().any() || obj->getSelectedFaces().any() ) )
return "";

return _tr( "There are no visible selected primitives." );
Expand Down
4 changes: 2 additions & 2 deletions source/MRIOExtras/MRGltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ Expected<void> serializeObjectTreeToGltf( const Object& root, const std::filesys
b[0], b[1], b[2], 1 };

auto curObjectMesh = curObj->asType<ObjectMesh>();
if ( curObjectMesh && curObjectMesh->mesh() )
if ( curObjectMesh && curObjectMesh->meshPtr() )
{
Material material;
material.baseColor = curObjectMesh->getFrontColor( false );
Expand Down Expand Up @@ -675,7 +675,7 @@ Expected<void> serializeObjectTreeToGltf( const Object& root, const std::filesys
materialIndex = materialIt->second;
}

const auto mesh = curObjectMesh->mesh();
const auto mesh = curObjectMesh->meshPtr();
const auto points = mesh->points;
const auto triangles = mesh->topology.getAllTriVerts();

Expand Down
2 changes: 1 addition & 1 deletion source/MRIOExtras/MRStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ struct StepLoader
{
objMesh = std::dynamic_pointer_cast<ObjectMesh>( objStack_.top() );
assert( objMesh );
assert( objMesh->mesh() );
assert( objMesh->meshPtr() );
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions source/MRMesh/MRChangeMeshAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ChangeMeshAction : public HistoryAction
{
if ( obj )
{
if ( auto m = obj->mesh() )
if ( auto m = obj->meshPtr() )
cloneMesh_ = std::make_shared<Mesh>( *m );
}
}
Expand Down Expand Up @@ -199,7 +199,7 @@ class ChangeMeshPointsAction : public HistoryAction
{
if ( !objMesh_ )
return;
if ( auto m = objMesh_->mesh() )
if ( auto m = objMesh_->meshPtr() )
clonePoints_ = m->points;
}

Expand Down Expand Up @@ -263,7 +263,7 @@ class ChangeMeshTopologyAction : public HistoryAction
{
if ( !objMesh_ )
return;
if ( auto m = objMesh_->mesh() )
if ( auto m = objMesh_->meshPtr() )
cloneTopology_ = m->topology;
}

Expand Down
6 changes: 3 additions & 3 deletions source/MRMesh/MRChangePointCloudAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ChangePointCloudAction : public HistoryAction
{
if ( obj )
{
if ( auto m = obj->pointCloud() )
if ( auto m = obj->pointCloudPtr() )
clonePointCloud_ = std::make_shared<PointCloud>( *m );
}
}
Expand Down Expand Up @@ -80,7 +80,7 @@ class ChangePointCloudPointsAction : public HistoryAction
{
if ( obj )
{
if ( auto m = obj->pointCloud() )
if ( auto m = obj->pointCloudPtr() )
clonePoints_ = m->points;
}
}
Expand Down Expand Up @@ -144,7 +144,7 @@ class ChangeOnePointInCloudAction : public HistoryAction
{
if ( obj )
{
if ( auto m = obj->pointCloud() )
if ( auto m = obj->pointCloudPtr() )
if ( m->points.size() > pointId_ )
safeCoords_ = m->points[pointId_];
}
Expand Down
4 changes: 2 additions & 2 deletions source/MRMesh/MRChangePointCloudNormalsAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ChangePointCloudNormalsAction : public HistoryAction
{
if ( obj )
{
if ( auto pc = obj->pointCloud() )
if ( auto pc = obj->pointCloudPtr() )
backupNormals_ = pc->normals;
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ class ChangeOneNormalInCloudAction : public HistoryAction
{
if ( obj )
{
if ( auto m = obj->pointCloud() )
if ( auto m = obj->pointCloudPtr() )
if ( m->normals.size() > pointId_ )
safeNormal_ = m->normals[pointId_];
}
Expand Down
8 changes: 4 additions & 4 deletions source/MRMesh/MRChangePolylineAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ChangePolylineAction : public HistoryAction
{
if ( obj )
{
if ( auto p = obj->polyline() )
if ( auto p = obj->polylinePtr() )
clonePolyline_ = std::make_shared<Polyline3>( *p );
}
}
Expand Down Expand Up @@ -82,7 +82,7 @@ class ChangePolylinePointsAction : public HistoryAction
{
if ( !objLines_ )
return;
if ( auto p = objLines_->polyline() )
if ( auto p = objLines_->polylinePtr() )
clonePoints_ = p->points;
}

Expand Down Expand Up @@ -143,7 +143,7 @@ class ChangePolylineTopologyAction : public HistoryAction
{
if ( !objLines_ )
return;
if ( auto p = objLines_->polyline() )
if ( auto p = objLines_->polylinePtr() )
cloneTopology_ = p->topology;
}

Expand Down Expand Up @@ -198,7 +198,7 @@ class ChangeOnePointInPolylineAction : public HistoryAction
{
if ( obj )
{
if ( auto m = obj->polyline() )
if ( auto m = obj->polylinePtr() )
if ( m->points.size() > pointId_ )
safeCoords_ = m->points[pointId_];
}
Expand Down
2 changes: 1 addition & 1 deletion source/MRMesh/MRMeshBooleanFacade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace MR

TransformedMesh MeshMeshConverter::operator() ( const ObjectMesh & obj ) const
{
return TransformedMesh( *obj.mesh(), obj.xf() );
return TransformedMesh( *obj.meshPtr(), obj.xf() );
}

TransformedMesh & operator += ( TransformedMesh & a, const TransformedMesh& b )
Expand Down
2 changes: 1 addition & 1 deletion source/MRMesh/MRObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class MRMESH_CLASS Object : public ObjectChildrenHolder
[[nodiscard]] virtual bool hasVisualRepresentation() const { return false; }

/// does the object have any model available (but possibly empty),
/// e.g. ObjectMesh has valid mesh() or ObjectPoints has valid pointCloud()
/// e.g. ObjectMesh has valid meshPtr() or ObjectPoints has valid pointCloudPtr()
[[nodiscard]] virtual bool hasModel() const { return false; }

/// provides read-only access to the tag storage
Expand Down
12 changes: 6 additions & 6 deletions source/MRMesh/MRObjectLines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ std::shared_ptr<ObjectLines> merge( const std::vector<std::shared_ptr<ObjectLine
bool hasVertColorMap = false; // least one input line has
for ( const auto& obj : objsLines )
{
if ( !obj->polyline() )
if ( !obj->polylinePtr() )
continue;
totalVerts += obj->polyline()->topology.numValidVerts();
totalVerts += obj->polylinePtr()->topology.numValidVerts();
if ( !obj->getVertsColorMap().empty() )
hasVertColorMap = true;
}
Expand All @@ -118,13 +118,13 @@ std::shared_ptr<ObjectLines> merge( const std::vector<std::shared_ptr<ObjectLine

for ( const auto& obj : objsLines )
{
if ( !obj->polyline() )
if ( !obj->polylinePtr() )
continue;

VertMap srcToMergeVmap;
UndirectedEdgeBitSet validPoints;
validPoints.resize( obj->polyline()->topology.undirectedEdgeSize(), true );
line->addPartByMask( *obj->polyline(), validPoints, &srcToMergeVmap );
validPoints.resize( obj->polylinePtr()->topology.undirectedEdgeSize(), true );
line->addPartByMask( *obj->polylinePtr(), validPoints, &srcToMergeVmap );

auto worldXf = obj->worldXf();
for ( const auto& vInd : srcToMergeVmap )
Expand Down Expand Up @@ -160,7 +160,7 @@ std::shared_ptr<ObjectLines> cloneRegion( const std::shared_ptr<ObjectLines>& ob
MR_TIMER;
std::shared_ptr<Polyline3> newPolyline = std::make_shared<Polyline3>();
VertMap src2clone;
newPolyline->addPartByMask( *objLines->polyline(), region, &src2clone );
newPolyline->addPartByMask( *objLines->polylinePtr(), region, &src2clone );
std::shared_ptr<ObjectLines> newObj = std::make_shared<ObjectLines>();
newObj->setFrontColor( objLines->getFrontColor( true ), true );
newObj->setFrontColor( objLines->getFrontColor( false ), false );
Expand Down
8 changes: 8 additions & 0 deletions source/MRMesh/MRObjectLinesHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,18 @@ class MRMESH_CLASS ObjectLinesHolder : public VisualObject
MRMESH_API virtual std::shared_ptr<Object> clone() const override;
MRMESH_API virtual std::shared_ptr<Object> shallowClone() const override;

/// returns the polyline of this object for modification, or nullptr if it is not set
[[nodiscard]] Polyline3* varPolylinePtr() { return polyline_.get(); }

/// returns the polyline of this object, or nullptr if it is not set
[[nodiscard]] const Polyline3* polylinePtr() const { return polyline_.get(); }

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing" // Fingers crossed.
#endif
/// \deprecated the cast inside is undefined behaviour, use polylinePtr() instead
[[deprecated( "use polylinePtr() instead" )]]
const std::shared_ptr<const Polyline3>& polyline() const
{ return reinterpret_cast< const std::shared_ptr<const Polyline3>& >( polyline_ ); } // reinterpret_cast to avoid making a copy of shared_ptr
#ifdef __GNUC__
Expand Down
4 changes: 2 additions & 2 deletions source/MRMesh/MRObjectLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void postImportObject( const std::shared_ptr<Object> &o, const std::filesystem::
bool flat;
if ( SceneSettings::getDefaultShadingMode() == SceneSettings::ShadingMode::AutoDetect )
flat = extension == ".step" || extension == ".stp" ||
( mesh->mesh() && detectFlatShading( *mesh->mesh().get() ) );
( mesh->meshPtr() && detectFlatShading( *mesh->meshPtr() ) );
else
flat = SceneSettings::getDefaultShadingMode() == SceneSettings::ShadingMode::Flat;
mesh->setVisualizeProperty( flat, MeshVisualizePropertyType::FlatShading, ViewportMask::all() );
Expand Down Expand Up @@ -480,7 +480,7 @@ Expected<LoadedObjects> loadObjectFromFile( const std::filesystem::path& filenam
postImportObject( o, filename );
if ( auto objectPoints = o->asType<ObjectPoints>(); objectPoints )
{
if ( !objectPoints->pointCloud()->hasNormals() )
if ( !objectPoints->pointCloudPtr()->hasNormals() )
result->warnings += "Point cloud " + o->name() + " has no normals.\n";
if ( objectPoints->getRenderDiscretization() > 1 )
result->warnings += "Point cloud " + o->name() + " has too many points in PointCloud:\n"
Expand Down
10 changes: 5 additions & 5 deletions source/MRMesh/MRObjectMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ std::shared_ptr<ObjectMesh> merge( const std::vector<std::shared_ptr<ObjectMesh>
{
MR_TIMER;
std::shared_ptr<ObjectMesh> res;
const auto firstNotEmptyIt = std::find_if( objsMesh.begin(), objsMesh.end(), []( const auto & p ) { return p && p->mesh(); } );
const auto firstNotEmptyIt = std::find_if( objsMesh.begin(), objsMesh.end(), []( const auto & p ) { return p && p->meshPtr(); } );
if ( firstNotEmptyIt == objsMesh.end() )
return res; // if no input object, then no output
res = std::make_shared<ObjectMesh>();
Expand All @@ -198,7 +198,7 @@ std::shared_ptr<ObjectMesh> merge( const std::vector<std::shared_ptr<ObjectMesh>
size_t numObject = 0;
for ( const auto& obj : objsMesh )
{
if ( auto curMesh = obj->mesh() )
if ( auto curMesh = obj->meshPtr() )
{
totalVerts += curMesh->topology.numValidVerts();
totalFaces += curMesh->topology.numValidFaces();
Expand Down Expand Up @@ -277,12 +277,12 @@ std::shared_ptr<ObjectMesh> merge( const std::vector<std::shared_ptr<ObjectMesh>
for ( int i = 0; i < objsMesh.size(); ++i )
{
const auto& obj = objsMesh[i];
if ( !obj->mesh() )
if ( !obj->meshPtr() )
continue;

VertMap vertMap;
FaceMap faceMap;
mesh->addMesh( *obj->mesh(), hasFaceColorMap || needTexturePerFace ? &faceMap : nullptr, &vertMap );
mesh->addMesh( *obj->meshPtr(), hasFaceColorMap || needTexturePerFace ? &faceMap : nullptr, &vertMap );

auto worldXf = options.overrideXfs && i < options.overrideXfs->size() ? ( *options.overrideXfs )[i] : obj->worldXf();
for ( const auto& vInd : vertMap )
Expand Down Expand Up @@ -413,7 +413,7 @@ std::shared_ptr<MR::ObjectMesh> cloneRegion( const std::shared_ptr<ObjectMesh>&
partMapping.tgt2srcVerts = &vertMap;
if ( !objMesh->getFacesColorMap().empty() || !objMesh->getTexturePerFace().empty() )
partMapping.tgt2srcFaces = &faceMap;
std::shared_ptr<Mesh> newMesh = std::make_shared<Mesh>( objMesh->mesh()->cloneRegion( region, false, partMapping ) );
std::shared_ptr<Mesh> newMesh = std::make_shared<Mesh>( objMesh->meshPtr()->cloneRegion( region, false, partMapping ) );
std::shared_ptr<ObjectMesh> newObj = std::make_shared<ObjectMesh>();
newObj->setFrontColor( objMesh->getFrontColor( true ), true );
newObj->setFrontColor( objMesh->getFrontColor( false ), false );
Expand Down
2 changes: 1 addition & 1 deletion source/MRMesh/MRObjectMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MRMESH_CLASS ObjectMesh : public ObjectMeshHolder
constexpr static const char* StaticClassNameInPlural() noexcept { return "Meshes"; }
virtual std::string classNameInPlural() const override { return StaticClassNameInPlural(); }

/// returns variable mesh, if const mesh is needed use `mesh()` instead
/// returns variable mesh, if const mesh is needed use `meshPtr()` instead
virtual const std::shared_ptr< Mesh > & varMesh() { return data_.mesh; }

/// sets given mesh to this, resets selection and creases
Expand Down
2 changes: 1 addition & 1 deletion source/MRMesh/MRObjectMeshHolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ void ObjectMeshHolder::copyTextureAndColors( const ObjectMeshHolder & src, const
}

const auto& srcUVCoords = src.getUVCoords();
const auto lastVert = src.mesh()->topology.lastValidVert();
const auto lastVert = src.meshPtr()->topology.lastValidVert();
const bool updateUV = lastVert < srcUVCoords.size();

if ( !updateUV )
Expand Down
8 changes: 8 additions & 0 deletions source/MRMesh/MRObjectMeshHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,18 @@ class MRMESH_CLASS ObjectMeshHolder : public VisualObject

[[nodiscard]] virtual bool hasModel() const override { return bool( data_.mesh ); }

/// returns the mesh of this object for modification, or nullptr if it is not set
[[nodiscard]] Mesh* varMeshPtr() { return data_.mesh.get(); }

/// returns the mesh of this object, or nullptr if it is not set
[[nodiscard]] const Mesh* meshPtr() const { return data_.mesh.get(); }

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing" // Fingers crossed.
#endif
/// \deprecated the cast inside is undefined behaviour, use meshPtr() instead
[[deprecated( "use meshPtr() instead" )]]
const std::shared_ptr< const Mesh >& mesh() const
{ return reinterpret_cast< const std::shared_ptr<const Mesh>& >( data_.mesh ); } // reinterpret_cast to avoid making a copy of shared_ptr
#ifdef __GNUC__
Expand Down
Loading
Loading