add relaxation (not very relaxing)
This commit is contained in:
parent
3467f8593d
commit
d31d9629f0
@ -2,6 +2,7 @@
|
|||||||
#include "remove_external_cells_filter.h"
|
#include "remove_external_cells_filter.h"
|
||||||
#include "surface_points_filter.h"
|
#include "surface_points_filter.h"
|
||||||
#include "project_surface_points_on_poly.h"
|
#include "project_surface_points_on_poly.h"
|
||||||
|
#include "relaxation_filter.h"
|
||||||
|
|
||||||
#include <vtkCellArrayIterator.h>
|
#include <vtkCellArrayIterator.h>
|
||||||
#include <vtkCellData.h>
|
#include <vtkCellData.h>
|
||||||
@ -79,8 +80,12 @@ int main(int argc, char **argv) {
|
|||||||
project->SetInputConnection(0, surfacePointsFilter->GetOutputPort());
|
project->SetInputConnection(0, surfacePointsFilter->GetOutputPort());
|
||||||
project->SetInputConnection(1, polyMeshReader->GetOutputPort());
|
project->SetInputConnection(1, polyMeshReader->GetOutputPort());
|
||||||
|
|
||||||
|
vtkNew<RelaxationFilter> relaxationFilter;
|
||||||
|
relaxationFilter->SetInputConnection(project->GetOutputPort());
|
||||||
|
|
||||||
vtkNew<DihedralAnglesFilter> dihedralAnglesFilter;
|
vtkNew<DihedralAnglesFilter> dihedralAnglesFilter;
|
||||||
dihedralAnglesFilter->SetInputConnection(project->GetOutputPort());
|
dihedralAnglesFilter->SetInputConnection(
|
||||||
|
relaxationFilter->GetOutputPort());
|
||||||
|
|
||||||
vtkNew<vtkXMLUnstructuredGridWriter> writer;
|
vtkNew<vtkXMLUnstructuredGridWriter> writer;
|
||||||
writer->SetInputConnection(dihedralAnglesFilter->GetOutputPort());
|
writer->SetInputConnection(dihedralAnglesFilter->GetOutputPort());
|
||||||
|
@ -154,10 +154,10 @@ vtkTypeBool ProjectSurfacePointsOnPoly::RequestData(
|
|||||||
vtkInformationVector **inputVector,
|
vtkInformationVector **inputVector,
|
||||||
vtkInformationVector *outputVector) {
|
vtkInformationVector *outputVector) {
|
||||||
(void) request;
|
(void) request;
|
||||||
vtkUnstructuredGrid* tetMesh = vtkUnstructuredGrid::GetData(inputVector[0]);
|
vtkUnstructuredGrid* tetMesh =
|
||||||
|
vtkUnstructuredGrid::GetData(inputVector[0]);
|
||||||
vtkPolyData* polyMesh = vtkPolyData::GetData(inputVector[1]);
|
vtkPolyData* polyMesh = vtkPolyData::GetData(inputVector[1]);
|
||||||
vtkUnstructuredGrid* output =
|
vtkUnstructuredGrid* output = vtkUnstructuredGrid::GetData(outputVector);
|
||||||
vtkUnstructuredGrid::GetData(outputVector);
|
|
||||||
|
|
||||||
output->CopyStructure(tetMesh);
|
output->CopyStructure(tetMesh);
|
||||||
output->GetPointData()->PassData(tetMesh->GetPointData());
|
output->GetPointData()->PassData(tetMesh->GetPointData());
|
||||||
|
@ -6,13 +6,59 @@
|
|||||||
#include <vtkDoubleArray.h>
|
#include <vtkDoubleArray.h>
|
||||||
#include <vtkCellIterator.h>
|
#include <vtkCellIterator.h>
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
vtkStandardNewMacro(RelaxationFilter);
|
vtkStandardNewMacro(RelaxationFilter);
|
||||||
|
|
||||||
vtkTypeBool RelaxationFilter::RequestData(
|
vtkTypeBool RelaxationFilter::RequestData(
|
||||||
vtkInformation *request,
|
vtkInformation *request,
|
||||||
vtkInformationVector **inputVector,
|
vtkInformationVector **inputVector,
|
||||||
vtkInformationVector *outputVector) {
|
vtkInformationVector *outputVector) {
|
||||||
|
(void) request;
|
||||||
|
vtkUnstructuredGrid* input =
|
||||||
|
vtkUnstructuredGrid::GetData(inputVector[0]);
|
||||||
|
vtkUnstructuredGrid* output = vtkUnstructuredGrid::GetData(outputVector);
|
||||||
|
output->CopyStructure(input);
|
||||||
|
output->GetPointData()->PassData(input->GetPointData());
|
||||||
|
output->GetCellData()->PassData(input->GetCellData());
|
||||||
|
vtkNew<vtkPoints> newPoints;
|
||||||
|
newPoints->DeepCopy(output->GetPoints());
|
||||||
|
vtkNew<vtkIdList> neighborCells;
|
||||||
|
vtkNew<vtkIdList> cellPoints;
|
||||||
|
vtkIntArray *isSurface = vtkIntArray::SafeDownCast(
|
||||||
|
output->GetPointData()->GetArray("isSurface"));
|
||||||
|
std::set<vtkIdType> neighbors;
|
||||||
|
output->BuildLinks();
|
||||||
|
double avg[3];
|
||||||
|
for (vtkIdType i = 0; i < output->GetNumberOfPoints(); i++) {
|
||||||
|
output->GetPointCells(i, neighborCells);
|
||||||
|
if (neighborCells->GetNumberOfIds() != 0) {
|
||||||
|
for (vtkIdType j = 0; j < neighborCells->GetNumberOfIds(); j++) {
|
||||||
|
vtkIdType cellId = neighborCells->GetId(j);
|
||||||
|
output->GetCellPoints(cellId, cellPoints);
|
||||||
|
for (vtkIdType k = 0; k < cellPoints->GetNumberOfIds(); k++) {
|
||||||
|
vtkIdType neighborId = cellPoints->GetId(k);
|
||||||
|
if (isSurface->GetValue(neighborId)) {
|
||||||
|
neighbors.insert(neighborId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cellPoints->Reset();
|
||||||
|
}
|
||||||
|
neighbors.erase(neighbors.find(i));
|
||||||
|
if (neighbors.size() != 0) {
|
||||||
|
avg[0] = 0; avg[1] = 0; avg[2] = 0;
|
||||||
|
for (const vtkIdType &j : neighbors) {
|
||||||
|
double point[3];
|
||||||
|
output->GetPoints()->GetPoint(j, point);
|
||||||
|
vtkMath::Add(point, avg, avg);
|
||||||
|
}
|
||||||
|
vtkMath::MultiplyScalar(avg, 1. / neighbors.size());
|
||||||
|
newPoints->SetPoint(i, avg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
neighborCells->Reset();
|
||||||
|
neighbors.clear();
|
||||||
|
}
|
||||||
|
output->SetPoints(newPoints);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user