Commit e84c4a5f authored by Charles Gueunet's avatar Charles Gueunet
Browse files

Add first version of AlphaWrapping

UNTESTED
parent 8d2f9efe
Pipeline #297181 failed with stages
in 1 minute and 48 seconds
set(vtkcgalpmp_files
vtkCGALPolyDataAlgorithm
vtkCGALAlphaWrapping
vtkCGALBooleanOperation
vtkCGALIsotropicRemesher
vtkCGALMeshDeformation
......
#include "vtkCGALAlphaWrapping.h"
// VTK related includes
#include "vtkDataSet.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
// CGAL related includes
#include <CGAL/alpha_wrap_3.h>
vtkStandardNewMacro(vtkCGALAlphaWrapping);
//------------------------------------------------------------------------------
void vtkCGALAlphaWrapping::PrintSelf(ostream& os, vtkIndent indent)
{
os << indent << "Alpha :" << this->Alpha << std::endl;
os << indent << "Offset :" << this->Offset << std::endl;
this->Superclass::PrintSelf(os, indent);
}
//------------------------------------------------------------------------------
int vtkCGALAlphaWrapping::RequestData(
vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
// Get the input and output data objects.
vtkPolyData* input = vtkPolyData::GetData(inputVector[0]);
vtkPolyData* output = vtkPolyData::GetData(outputVector);
// input parameters
auto length = input->GetLength();
if (this->Alpha <= 0)
{
vtkErrorMacro("Please, specify a positive Alpha: " << this->Alpha);
return 0;
}
auto alpha = length / this->Alpha;
if (this->Offset <= 0)
{
vtkErrorMacro("Please, specify a positive Offset: " << this->Offset);
return 0;
}
auto offset = length / this->Offset;
// Create the surface mesh for CGAL
// --------------------------------
std::unique_ptr<CGAL_Mesh> cgalInput = this->toCGAL(input);
std::unique_ptr<CGAL_Mesh> cgalOutput = std::make_unique<CGAL_Mesh>();
// CGAL Processing
// ---------------
try
{
CGAL::alpha_wrap_3(cgalInput->surface, this->Alpha, this->Offset, cgalOutput->surface);
}
catch (std::exception& e)
{
vtkErrorMacro("CGAL Exception: " << e.what());
return 0;
}
// VTK Output
// ----------
output->ShallowCopy(this->toVTK(cgalOutput.get()));
this->interpolateAttributes(input, output);
return 1;
}
/**
* @class vtkCGALAlphaWrapping
* @brief remesh using the CGAL isotropic remeshing
*
* vtkCGALAlphaWrapping is a filter allowing to reconstruct
* a 2-manifold from an arbitrary polygon soup
*/
#ifndef vtkCGALAlphaWrapping_h
#define vtkCGALAlphaWrapping_h
#include "vtkCGALPolyDataAlgorithm.h"
#include "vtkCGALPMPModule.h" // For export macro
class VTKCGALPMP_EXPORT vtkCGALAlphaWrapping : public vtkCGALPolyDataAlgorithm
{
public:
static vtkCGALAlphaWrapping* New();
vtkTypeMacro(vtkCGALAlphaWrapping, vtkCGALPolyDataAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) override;
//@{
/**
* Get / Set the alpha property, a small alpha
* lead to a finer reconstruction (but more computation).
* The value is relative to the diagonal lenght of the input
**/
vtkGetMacro(Alpha, double);
vtkSetMacro(Alpha, double);
//@}
//@{
/**
* Get / Set the offset property, drive a dilatation
* on the resulting mesh. The goal is to fix degenerancies
* and keep a 2-manifold output.
* The value is relative to the diagonal lenght of the input
**/
vtkGetMacro(Offset, double);
vtkSetMacro(Offset, double);
//@}
protected:
vtkCGALAlphaWrapping() = default;
~vtkCGALAlphaWrapping() override = default;
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
// Fields
double Alpha = 5;
double Offset = 3;
private:
vtkCGALAlphaWrapping(const vtkCGALAlphaWrapping&) = delete;
void operator=(const vtkCGALAlphaWrapping&) = delete;
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment