Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] FILTER: RemoveFlaggedTriangles. #678

Closed
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
2 changes: 2 additions & 0 deletions src/Plugins/ComplexCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ set(FilterList
ReadVolumeGraphicsFileFilter
RegularGridSampleSurfaceMeshFilter
RemoveFlaggedFeaturesFilter
RemoveFlaggedTrianglesFilter
RemoveFlaggedVertices
RemoveMinimumSizeFeaturesFilter
RenameDataObject
Expand Down Expand Up @@ -183,6 +184,7 @@ set(AlgorithmList
ReadVolumeGraphicsFile
RegularGridSampleSurfaceMesh
RemoveFlaggedFeatures
RemoveFlaggedTriangles
ReplaceElementAttributesWithNeighborValues
ResampleImageGeom
ResampleRectGridToImageGeom
Expand Down
51 changes: 51 additions & 0 deletions src/Plugins/ComplexCore/docs/RemoveFlaggedTrianglesFilter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Remove Flagged Triangles #

## Group (Subgroup) ##

Surface Meshing (Misc)

## Description ##

This **Filter** removes **Triangles** from the supplied **Triangle Geometry** that are flagged by a boolean mask array.
Specifically, **Triangles** flagged as _true_ are removed from the **Geometry**. A new reduced **Triangle Geometry** is created
that contains all the remaining **Triangles**. It is unknown until run time how many **Triangles** will be removed from the
**Geometry**. Therefore, this **Filter** requires that a new **Data Container** be created to contain the reduced **Triangle Geometry**.
This new **Data Container** will NOT contain copies of any **Feature** or **Ensemble** **Attribute Matrices** from the original **Data Container**.
Additionally, all **Vertex** data will be copied, with tuples _removed_ for any **Vertices** removed by the **Filter**.
The user must supply a name for the reduced **Data Container**.

_Note:_ Since it cannot be known before run time how many **Vertices** will be removed, the new **Vertex Geometry** and
all associated **Vertex** data to be copied will be initialized to have size 0.

## Parameters ##

None

## Required Geometry ###

**Triangle Geometry**

## Required Objects ##

| Kind | Default Name | Type | Component Dimensions | Description |
|------|--------------|------|----------------------|---------------------------------------------------------------------|
| **Data Container** | TriangleDataContainer | N/A | N/A | **Data Container** holding the **Triangle Geometry** to reduce |
| **Triangle Attribute Array** | Mask | bool | (1) | Mask array specifying which **Triangles** to remove |

## Created Objects ##

| Kind | Default Name | Type | Component Dimensions | Description |
|----------------------------|----------------------------|------|----------------------|------------------------------------------------------------|
| Reduced **Data Container** | ReducedVertexDataContainer | N/A | N/A | **Data Container** holding the reduced **Vertex Geometry** |

## Example Pipelines ##



## License & Copyright ##

Please see the description file distributed with this plugin.

## DREAM3D Mailing Lists ##

If you need more help with a filter, please consider asking your question on the DREAM3D Users mailing list:
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
#include <string>

// clang-format off
#include "ComplexCore/Filters/WriteAbaqusHexahedronFilter.hpp"
#include "ComplexCore/Filters/AddBadDataFilter.hpp"
#include "ComplexCore/Filters/AlignGeometries.hpp"
#include "ComplexCore/Filters/AlignSectionsFeatureCentroidFilter.hpp"
#include "ComplexCore/Filters/AlignSectionsListFilter.hpp"
#include "ComplexCore/Filters/AppendImageGeometryZSliceFilter.hpp"
#include "ComplexCore/Filters/ApplyTransformationToGeometryFilter.hpp"
#include "ComplexCore/Filters/ApplyTransformationToGeometryFilter.hpp"
#include "ComplexCore/Filters/ApproximatePointCloudHull.hpp"
#include "ComplexCore/Filters/ArrayCalculatorFilter.hpp"
#include "ComplexCore/Filters/WriteAvizoRectilinearCoordinateFilter.hpp"
#include "ComplexCore/Filters/WriteAvizoUniformCoordinateFilter.hpp"
#include "ComplexCore/Filters/CalculateArrayHistogramFilter.hpp"
#include "ComplexCore/Filters/CalculateFeatureSizesFilter.hpp"
#include "ComplexCore/Filters/CalculateTriangleAreasFilter.hpp"
#include "ComplexCore/Filters/ChangeAngleRepresentation.hpp"
#include "ComplexCore/Filters/CombineAttributeArraysFilter.hpp"
#include "ComplexCore/Filters/CombineStlFilesFilter.hpp"
#include "ComplexCore/Filters/ComputeFeatureRectFilter.hpp"
#include "ComplexCore/Filters/ComputeMomentInvariants2DFilter.hpp"
#include "ComplexCore/Filters/ConditionalSetValue.hpp"
#include "ComplexCore/Filters/ConvertColorToGrayScaleFilter.hpp"
#include "ComplexCore/Filters/ConvertDataFilter.hpp"
Expand All @@ -28,31 +37,37 @@
#include "ComplexCore/Filters/CropImageGeometry.hpp"
#include "ComplexCore/Filters/CropVertexGeometry.hpp"
#include "ComplexCore/Filters/DeleteData.hpp"
#include "ComplexCore/Filters/ErodeDilateBadDataFilter.hpp"
#include "ComplexCore/Filters/ErodeDilateCoordinationNumberFilter.hpp"
#include "ComplexCore/Filters/ErodeDilateMaskFilter.hpp"
#include "ComplexCore/Filters/ErodeDilateBadDataFilter.hpp"
#include "ComplexCore/Filters/ExecuteProcessFilter.hpp"
#include "ComplexCore/Filters/ExecuteProcessFilter.hpp"
#include "ComplexCore/Filters/WriteDREAM3DFilter.hpp"
#include "ComplexCore/Filters/ExtractComponentAsArrayFilter.hpp"
#include "ComplexCore/Filters/ExtractInternalSurfacesFromTriangleGeometry.hpp"
#include "ComplexCore/Filters/WriteFeatureDataCSVFilter.hpp"
#include "ComplexCore/Filters/FillBadDataFilter.hpp"
#include "ComplexCore/Filters/FindArrayStatisticsFilter.hpp"
#include "ComplexCore/Filters/FindBoundaryCellsFilter.hpp"
#include "ComplexCore/Filters/FindBiasedFeaturesFilter.hpp"
#include "ComplexCore/Filters/FindBoundaryCellsFilter.hpp"
#include "ComplexCore/Filters/FindBoundaryElementFractionsFilter.hpp"
#include "ComplexCore/Filters/FindDifferencesMap.hpp"
#include "ComplexCore/Filters/FindEuclideanDistMapFilter.hpp"
#include "ComplexCore/Filters/FindFeatureCentroidsFilter.hpp"
#include "ComplexCore/Filters/FindFeaturePhasesFilter.hpp"
#include "ComplexCore/Filters/FindFeatureClusteringFilter.hpp"
#include "ComplexCore/Filters/FindFeaturePhasesBinaryFilter.hpp"
#include "ComplexCore/Filters/FindFeaturePhasesFilter.hpp"
#include "ComplexCore/Filters/FindLargestCrossSectionsFilter.hpp"
#include "ComplexCore/Filters/FindNeighborhoodsFilter.hpp"
#include "ComplexCore/Filters/FindNeighborListStatistics.hpp"
#include "ComplexCore/Filters/FindNeighbors.hpp"
#include "ComplexCore/Filters/FindNumFeaturesFilter.hpp"
#include "ComplexCore/Filters/FindSurfaceAreaToVolumeFilter.hpp"
#include "ComplexCore/Filters/FindSurfaceFeatures.hpp"
#include "ComplexCore/Filters/FindVertexToTriangleDistancesFilter.hpp"
#include "ComplexCore/Filters/FindVolFractionsFilter.hpp"
#include "ComplexCore/Filters/GenerateColorTableFilter.hpp"
#include "ComplexCore/Filters/GenerateVectorColorsFilter.hpp"
#include "ComplexCore/Filters/IdentifySample.hpp"
#include "ComplexCore/Filters/ReadBinaryCTNorthstarFilter.hpp"
#include "ComplexCore/Filters/ReadCSVFileFilter.hpp"
Expand All @@ -64,36 +79,39 @@
#include "ComplexCore/Filters/InitializeData.hpp"
#include "ComplexCore/Filters/InterpolatePointCloudToRegularGridFilter.hpp"
#include "ComplexCore/Filters/IterativeClosestPointFilter.hpp"
#include "ComplexCore/Filters/KMeansFilter.hpp"
#include "ComplexCore/Filters/KMedoidsFilter.hpp"
#include "ComplexCore/Filters/LaplacianSmoothingFilter.hpp"
#include "ComplexCore/Filters/WriteLosAlamosFFTFilter.hpp"
#include "ComplexCore/Filters/MapPointCloudToRegularGridFilter.hpp"
#include "ComplexCore/Filters/MinNeighbors.hpp"
#include "ComplexCore/Filters/MoveData.hpp"
#include "ComplexCore/Filters/MultiThresholdObjects.hpp"
#include "ComplexCore/Filters/NearestPointFuseRegularGridsFilter.hpp"
#include "ComplexCore/Filters/PointSampleTriangleGeometryFilter.hpp"
#include "ComplexCore/Filters/QuickSurfaceMeshFilter.hpp"
#include "ComplexCore/Filters/ReadRawBinaryFilter.hpp"
#include "ComplexCore/Filters/RemoveFlaggedTrianglesFilter.hpp"
#include "ComplexCore/Filters/RemoveFlaggedVertices.hpp"
#include "ComplexCore/Filters/RemoveMinimumSizeFeaturesFilter.hpp"
#include "ComplexCore/Filters/RenameDataObject.hpp"
#include "ComplexCore/Filters/ReplaceElementAttributesWithNeighborValuesFilter.hpp"
#include "ComplexCore/Filters/ResampleImageGeomFilter.hpp"
#include "ComplexCore/Filters/ResampleRectGridToImageGeomFilter.hpp"
#include "ComplexCore/Filters/ReverseTriangleWindingFilter.hpp"
#include "ComplexCore/Filters/RobustAutomaticThreshold.hpp"
#include "ComplexCore/Filters/RotateSampleRefFrameFilter.hpp"
#include "ComplexCore/Filters/ScalarSegmentFeaturesFilter.hpp"
#include "ComplexCore/Filters/SetImageGeomOriginScalingFilter.hpp"
#include "ComplexCore/Filters/SilhouetteFilter.hpp"
#include "ComplexCore/Filters/SplitAttributeArrayFilter.hpp"
#include "ComplexCore/Filters/ReadStlFileFilter.hpp"
#include "ComplexCore/Filters/TriangleCentroidFilter.hpp"
#include "ComplexCore/Filters/TriangleDihedralAngleFilter.hpp"
#include "ComplexCore/Filters/TriangleNormalFilter.hpp"
#include "ComplexCore/Filters/UncertainRegularGridSampleSurfaceMeshFilter.hpp"
#include "ComplexCore/Filters/WriteVtkRectilinearGridFilter.hpp"
#include "ComplexCore/Filters/WriteASCIIDataFilter.hpp"
#include "ComplexCore/Filters/RemoveFlaggedFeaturesFilter.hpp"
#include "ComplexCore/Filters/ComputeMomentInvariants2DFilter.hpp"
#include "ComplexCore/Filters/ExecuteProcessFilter.hpp"
#include "ComplexCore/Filters/FindVertexToTriangleDistancesFilter.hpp"
#include "ComplexCore/Filters/ApplyTransformationToGeometryFilter.hpp"
#include "ComplexCore/Filters/ComputeFeatureRectFilter.hpp"
#include "ComplexCore/Filters/FindLargestCrossSectionsFilter.hpp"
#include "ComplexCore/Filters/WriteStlFileFilter.hpp"
#include "ComplexCore/Filters/AddBadDataFilter.hpp"
#include "ComplexCore/Filters/AppendImageGeometryZSliceFilter.hpp"
Expand All @@ -114,6 +132,8 @@
#include "ComplexCore/Filters/KMedoidsFilter.hpp"
#include "ComplexCore/Filters/KMeansFilter.hpp"
#include "ComplexCore/Filters/SilhouetteFilter.hpp"
#include "ComplexCore/Filters/RemoveFlaggedFeaturesFilter.hpp"
#include "ComplexCore/Filters/RemoveFlaggedTrianglesFilter.hpp"
// @@__HEADER__TOKEN__DO__NOT__DELETE__@@

namespace complex
Expand Down Expand Up @@ -237,6 +257,7 @@ namespace complex
{complex::Uuid::FromString("f7486aa6-3049-5be7-8511-ae772b70c90b").value(), complex::FilterTraits<KMedoidsFilter>::uuid}, // KMedoids
{complex::Uuid::FromString("b56a04de-0ca0-509d-809f-52219fca9c98").value(), complex::FilterTraits<KMeansFilter>::uuid}, // KMeans
{complex::Uuid::FromString("f84d4d69-9ea5-54b6-a71c-df76d76d50cf").value(), complex::FilterTraits<SilhouetteFilter>::uuid}, // Silhouette
{complex::Uuid::FromString("379ccc67-16dd-530a-984f-177db9351bac").value(), complex::FilterTraits<RemoveFlaggedTrianglesFilter>::uuid}, // RemoveFlaggedTriangles
// @@__MAP__UPDATE__TOKEN__DO__NOT__DELETE__@@
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#include "RemoveFlaggedTriangles.hpp"

#include "complex/DataStructure/DataArray.hpp"
#include "complex/DataStructure/DataGroup.hpp"
#include "complex/DataStructure/Geometry/TriangleGeom.hpp"
#include "complex/Utilities/ParallelDataAlgorithm.hpp"

using namespace complex;

namespace
{
/**
* @brief The PopulateReducedGeometryTrianglesImpl pulls the vertices associated with a triangle then locates the indices in
* the new VertexList then assigns that "new" triangle to Reduced Geometry
*/
class PopulateReducedGeometryTrianglesImpl
{
public:
PopulateReducedGeometryTrianglesImpl(const TriangleGeom& originalTriangle, TriangleGeom& reducedTriangle, const std::vector<usize>& newTrianglesIndex, const std::vector<usize>& newVerticesIndex)
: m_OriginalTriangle(originalTriangle)
, m_ReducedTriangle(reducedTriangle)
, m_NewTrianglesIndex(newTrianglesIndex)
, m_NewVerticesIndex(newVerticesIndex)
{
}
~PopulateReducedGeometryTrianglesImpl() = default;

void generate(usize start, usize end) const
{
for(usize index = start; index < end; index++)
{
// pull old vertices
Point3Df oldVertexIndices = m_OriginalTriangle.getVertexCoordinate(m_NewTrianglesIndex[index]);

// locate new vertex index for each vertex index
usize newVertexIndices[3] = {0, 0, 0};
for(usize vertIndex = 0; vertIndex < 3; vertIndex++)
{
const auto& itr = lower_bound(m_NewVerticesIndex.begin(), m_NewVerticesIndex.end(), oldVertexIndices[vertIndex]); // find first instance of value as iterator
usize indexOfTarget = std::distance(m_NewVerticesIndex.begin(), itr);
newVertexIndices[vertIndex] = indexOfTarget;
}

// set the triangle in reduced
m_ReducedTriangle.setFacePointIds(index, newVertexIndices);
}
}

void operator()(const Range& range) const
{
generate(range.min(), range.max());
}

private:
const TriangleGeom& m_OriginalTriangle;
TriangleGeom& m_ReducedTriangle;
const std::vector<usize>& m_NewTrianglesIndex;
const std::vector<usize>& m_NewVerticesIndex;
};
} // namespace

// -----------------------------------------------------------------------------
RemoveFlaggedTriangles::RemoveFlaggedTriangles(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel,
RemoveFlaggedTrianglesInputValues* inputValues)
: m_DataStructure(dataStructure)
, m_InputValues(inputValues)
, m_ShouldCancel(shouldCancel)
, m_MessageHandler(mesgHandler)
{
}

// -----------------------------------------------------------------------------
const std::atomic_bool& RemoveFlaggedTriangles::getCancel()
{
return m_ShouldCancel;
}

// -----------------------------------------------------------------------------
Result<> RemoveFlaggedTriangles::operator()()
{
// Remove Triangles from reduced according to removeTrianglesIndex
const auto& originalTriangle = m_DataStructure.getDataRefAs<TriangleGeom>(m_InputValues->TriangleGeometry);
const auto& mask = m_DataStructure.getDataRefAs<BoolArray>(m_InputValues->MaskArrayPath);
auto& reducedTriangle = m_DataStructure.getDataRefAs<TriangleGeom>(m_InputValues->ReducedTriangleGeometry);

// Set up allocated masks
usize size = originalTriangle.getNumberOfFaces();
std::vector<usize> newTrianglesIndexList;
newTrianglesIndexList.reserve(size);

// parse mask Triangles list and load a list of indices for triangles to keep
for(usize index = 0; index < size; index++)
{
if(!mask[index])
{
newTrianglesIndexList.push_back(index);
}
}
newTrianglesIndexList.shrink_to_fit();

if(getCancel())
{
return {};
}
if(newTrianglesIndexList.empty())
{
return MakeErrorResult(-67880, "Re-evaluate mask conditions - with current configuration all triangles will be stripped!");
}

// flatten a list of the indices of vertices used by the triangles
std::vector<usize> pseudoVertexList; // also used as a pseudo look up table in PopulateReducedGeometryTrianglesImpl
for(usize& index : newTrianglesIndexList)
{
usize vertIDs[3] = {0, 0, 0};
originalTriangle.getFacePointIds(index, vertIDs);
pseudoVertexList.push_back(vertIDs[0]);
pseudoVertexList.push_back(vertIDs[1]);
pseudoVertexList.push_back(vertIDs[2]);
}
if(getCancel())
{
return {};
}

if(pseudoVertexList.empty())
{
return MakeErrorResult(-67881, "Re-evaluate mask conditions - with current configuration all vertices will be dumped!");
}

// clear duplicate values out of vector
std::sort(pseudoVertexList.begin(), pseudoVertexList.end()); // orders ascending !!!!! Basis for later search !!!!!
auto dupes = std::unique(pseudoVertexList.begin(), pseudoVertexList.end());
pseudoVertexList.erase(dupes, pseudoVertexList.end());

// define new sizing
size = pseudoVertexList.size();
reducedTriangle.resizeVertexList(size); // resize accordingly

// load reduced Geometry Vertex list according to used vertices
Point3Df coords = {0.0f, 0.0f, 0.0f};
for(usize i = 0; i < size; i++)
{
coords = originalTriangle.getVertexCoordinate(pseudoVertexList[i]);
reducedTriangle.setVertexCoordinate(i, coords);
}

if(getCancel())
{
return {};
}

// Set up preprocessing conditions (allocation for parallelization)
reducedTriangle.resizeFaceList(newTrianglesIndexList.size()); // resize accordingly

// parse triangles and reassign indexes to match new vertex list
ParallelDataAlgorithm dataAlg;
dataAlg.setRange(0, size);
dataAlg.execute(PopulateReducedGeometryTrianglesImpl(originalTriangle, reducedTriangle, newTrianglesIndexList, pseudoVertexList));

return {};
}
Loading
Loading