-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unusable and hard-coded for now. General idea is to define regions of planarity among meshes and store these regions separately. This shall be used for removing planar parts of an arbitrary mesh. Ideas so far: * Use RMS curvature * Identify "almost" planar vertices * _Try_ to identify a region containing these vertices * Make this region as large as possible This requires severe changes in the mesh class. Namely, it should be possible to _copy_ parts of the mesh -- not a great idea as the vertex indices might change.
- Loading branch information
1 parent
560b128
commit eea9d53
Showing
7 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SET( SEGMENTATION_ALGORITHMS_SRC | ||
SegmentationAlgorithm.cpp | ||
PlanarSegmentation.cpp | ||
) | ||
|
||
ADD_LIBRARY(SegmentationAlgorithms SHARED ${SEGMENTATION_ALGORITHMS_SRC}) | ||
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/*! | ||
* @file PlanarSegmentation.cpp | ||
* @brief Functions for the planar segmentation algorithm | ||
*/ | ||
|
||
#include "PlanarSegmentation.h" | ||
|
||
namespace psalm | ||
{ | ||
|
||
/*! | ||
* Performs a planar segmentation to the input mesh: Planar vertices are | ||
* identified by calculating the discrete mean curvature of a vertex. If | ||
* all planar vertices have been identified, edges leading to planar | ||
* vertices will be inserted into a new, which is returned as the | ||
* function's result. | ||
* | ||
* @param input_mesh Mesh for which the planar segmentation shall be | ||
* performed | ||
* | ||
* @return Segmented mesh | ||
*/ | ||
|
||
mesh PlanarSegmentation::apply_to(mesh& input_mesh) | ||
{ | ||
mesh res; | ||
|
||
/* | ||
* FIXME: This assumes that the vertex IDs are numbered | ||
* sequentially. If this is not the case, the function will | ||
* fail... | ||
*/ | ||
|
||
// Identify planar vertices | ||
|
||
size_t n = input_mesh.num_vertices(); | ||
bool* is_planar = new bool[n]; | ||
|
||
for(size_t i = 0; i < n; i++) | ||
{ | ||
vertex* v = input_mesh.get_vertex(i); | ||
double curvature = v->calc_mean_curvature(); | ||
|
||
if(curvature < 0.005) | ||
is_planar[i] = true; | ||
else | ||
is_planar[i] = false; | ||
} | ||
|
||
for(size_t i = 0; i < input_mesh.num_faces(); i++) | ||
{ | ||
face* f = input_mesh.get_face(i); | ||
|
||
size_t non_planar = 0; | ||
for(size_t j = 0; j < f->num_vertices(); j++) | ||
{ | ||
if(!is_planar[f->get_vertex(j)->get_id()]) | ||
non_planar++; | ||
} | ||
|
||
if(non_planar > 1) | ||
continue; | ||
|
||
vertex* v1 = res.add_vertex(f->get_vertex(0)->get_position()); | ||
vertex* v2 = res.add_vertex(f->get_vertex(1)->get_position()); | ||
vertex* v3 = res.add_vertex(f->get_vertex(2)->get_position()); | ||
|
||
res.add_face(v1,v2,v3); | ||
} | ||
|
||
delete[] is_planar; | ||
return(res); | ||
} | ||
|
||
} // end of namespace "psalm" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/*! | ||
* @file PlanarSegmentation.h | ||
* @brief Class describing a planar segmentation algorithm | ||
*/ | ||
|
||
#ifndef __PLANAR_SEGMENTATION_H__ | ||
#define __PLANAR_SEGMENTATION_H__ | ||
|
||
#include "SegmentationAlgorithm.h" | ||
|
||
namespace psalm | ||
{ | ||
|
||
/*! | ||
* @class PlanarSegmentation | ||
* @brief Describes algorithm for performing a planar segmentation of an | ||
* input mesh | ||
*/ | ||
|
||
class PlanarSegmentation : public SegmentationAlgorithm | ||
{ | ||
public: | ||
mesh apply_to(mesh& input_mesh); | ||
}; | ||
|
||
} // end of namespace "psalm" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*! | ||
* @file SegmentationAlgorithm.cpp | ||
* @brief Implementation of generic functions for segmentation algorithms | ||
*/ | ||
|
||
#include "SegmentationAlgorithm.h" | ||
|
||
namespace psalm | ||
{ | ||
|
||
/*! | ||
* Empty constructor | ||
*/ | ||
|
||
SegmentationAlgorithm::SegmentationAlgorithm() | ||
{ | ||
} | ||
|
||
} // end of namespace "libpsalm" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*! | ||
* @file SegmentationAlgorithm.h | ||
* @brief Generic (abstract) class for segmentation algorithms | ||
*/ | ||
|
||
#ifndef __SEGMENTATION_ALGORITHM_H__ | ||
#define __SEGMENTATION_ALGORIOTM_H__ | ||
|
||
#include "mesh.h" | ||
|
||
namespace psalm | ||
{ | ||
|
||
/*! | ||
* @class SegmentationAlgorithm | ||
* @brief Generic segmentation algorithm class | ||
*/ | ||
|
||
class SegmentationAlgorithm | ||
{ | ||
public: | ||
SegmentationAlgorithm(); | ||
|
||
virtual mesh apply_to(mesh& input_mesh) = 0; | ||
}; | ||
|
||
} // end of namespace "psalm" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters