fix relaxation + radius arg
This commit is contained in:
parent
d31d9629f0
commit
a60191b068
11
src/main.cc
11
src/main.cc
@ -16,6 +16,7 @@
|
|||||||
#include <vtkXMLUnstructuredGridReader.h>
|
#include <vtkXMLUnstructuredGridReader.h>
|
||||||
#include <vtkXMLUnstructuredGridWriter.h>
|
#include <vtkXMLUnstructuredGridWriter.h>
|
||||||
#include <vtksys/SystemTools.hxx>
|
#include <vtksys/SystemTools.hxx>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#ifdef USE_VIEWER
|
#ifdef USE_VIEWER
|
||||||
#include <vtkCamera.h>
|
#include <vtkCamera.h>
|
||||||
@ -58,11 +59,16 @@ vtkSmartPointer<vtkAlgorithm> readerFromFileName(const char *fileName) {
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
if (argc != 3) {
|
if (argc < 3 || argc > 5) {
|
||||||
std::cerr << "Usage: " << argv[0] << " tetmesh polydata" << std::endl;
|
std::cerr << "Usage: " << argv[0] << " tetmesh polydata [radiusScale]" << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double radiusScale = 2.;
|
||||||
|
if(argc == 4) {
|
||||||
|
radiusScale = std::stod(argv[3]);
|
||||||
|
}
|
||||||
|
|
||||||
auto tetMeshReader = readerFromFileName(argv[1]);
|
auto tetMeshReader = readerFromFileName(argv[1]);
|
||||||
auto polyMeshReader = readerFromFileName(argv[2]);
|
auto polyMeshReader = readerFromFileName(argv[2]);
|
||||||
|
|
||||||
@ -77,6 +83,7 @@ int main(int argc, char **argv) {
|
|||||||
removeExternalCellsFilter->GetOutputPort());
|
removeExternalCellsFilter->GetOutputPort());
|
||||||
|
|
||||||
vtkNew<ProjectSurfacePointsOnPoly> project;
|
vtkNew<ProjectSurfacePointsOnPoly> project;
|
||||||
|
project->SetRadiusScale(radiusScale);
|
||||||
project->SetInputConnection(0, surfacePointsFilter->GetOutputPort());
|
project->SetInputConnection(0, surfacePointsFilter->GetOutputPort());
|
||||||
project->SetInputConnection(1, polyMeshReader->GetOutputPort());
|
project->SetInputConnection(1, polyMeshReader->GetOutputPort());
|
||||||
|
|
||||||
|
@ -9,9 +9,6 @@
|
|||||||
#include <vtkCellIterator.h>
|
#include <vtkCellIterator.h>
|
||||||
#include <vtkInformation.h>
|
#include <vtkInformation.h>
|
||||||
#include <vtkInformationVector.h>
|
#include <vtkInformationVector.h>
|
||||||
#include <vtkPolyData.h>
|
|
||||||
#include <vtkKdTree.h>
|
|
||||||
#include <vtkStaticCellLinks.h>
|
|
||||||
#include <vtkDoubleArray.h>
|
#include <vtkDoubleArray.h>
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@ -22,6 +19,8 @@ vtkStandardNewMacro(ProjectSurfacePointsOnPoly);
|
|||||||
|
|
||||||
ProjectSurfacePointsOnPoly::ProjectSurfacePointsOnPoly() {
|
ProjectSurfacePointsOnPoly::ProjectSurfacePointsOnPoly() {
|
||||||
SetNumberOfInputPorts(2);
|
SetNumberOfInputPorts(2);
|
||||||
|
|
||||||
|
RadiusScale = 2.;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -84,7 +83,7 @@ void findPointsWithinRadius(double radius, vtkPointSet *pointSet,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void moveSurfacePoint(vtkUnstructuredGrid *tetMesh,
|
void ProjectSurfacePointsOnPoly::moveSurfacePoint(vtkUnstructuredGrid *tetMesh,
|
||||||
vtkPolyData *polyMesh,
|
vtkPolyData *polyMesh,
|
||||||
vtkIdType pointId,
|
vtkIdType pointId,
|
||||||
std::vector<double> &motionVectors,
|
std::vector<double> &motionVectors,
|
||||||
@ -96,11 +95,9 @@ static void moveSurfacePoint(vtkUnstructuredGrid *tetMesh,
|
|||||||
double direction[3];
|
double direction[3];
|
||||||
double distance;
|
double distance;
|
||||||
|
|
||||||
double radiusScale = 5.;
|
|
||||||
|
|
||||||
closestPolyMeshPoint(polyMesh, point, kdTree, links, direction, &distance);
|
closestPolyMeshPoint(polyMesh, point, kdTree, links, direction, &distance);
|
||||||
vtkNew<vtkIdList> affectedPoints;
|
vtkNew<vtkIdList> affectedPoints;
|
||||||
findPointsWithinRadius(distance * radiusScale, tetMesh, point, affectedPoints);
|
findPointsWithinRadius(distance * RadiusScale, tetMesh, point, affectedPoints);
|
||||||
// kdTree->FindPointsWithinRadius(distance * radiusScale, point, affectedPoints);
|
// kdTree->FindPointsWithinRadius(distance * radiusScale, point, affectedPoints);
|
||||||
|
|
||||||
if(distance > 0) for (vtkIdType j = 0; j < affectedPoints->GetNumberOfIds(); j++) {
|
if(distance > 0) for (vtkIdType j = 0; j < affectedPoints->GetNumberOfIds(); j++) {
|
||||||
@ -111,7 +108,7 @@ static void moveSurfacePoint(vtkUnstructuredGrid *tetMesh,
|
|||||||
// if(dist2 > (distance * radiusScale) * (distance * radiusScale)) continue;
|
// if(dist2 > (distance * radiusScale) * (distance * radiusScale)) continue;
|
||||||
|
|
||||||
double motion[3] = {direction[0], direction[1], direction[2]};
|
double motion[3] = {direction[0], direction[1], direction[2]};
|
||||||
double factor = 1. - std::sqrt(dist2) / (distance * radiusScale);
|
double factor = 1. - std::sqrt(dist2) / (distance * RadiusScale);
|
||||||
vtkMath::MultiplyScalar(motion, factor);
|
vtkMath::MultiplyScalar(motion, factor);
|
||||||
//std::cout << std::sqrt(dist2) << " " << (distance * radiusScale) << " " << factor << "\n";
|
//std::cout << std::sqrt(dist2) << " " << (distance * radiusScale) << " " << factor << "\n";
|
||||||
motionVectors[affectedPointId * 3 + 0] += motion[0];
|
motionVectors[affectedPointId * 3 + 0] += motion[0];
|
||||||
|
@ -3,7 +3,10 @@
|
|||||||
|
|
||||||
#include <vtkUnstructuredGridAlgorithm.h>
|
#include <vtkUnstructuredGridAlgorithm.h>
|
||||||
#include <vtkIdList.h>
|
#include <vtkIdList.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <vtkPolyData.h>
|
||||||
|
#include <vtkKdTree.h>
|
||||||
|
#include <vtkStaticCellLinks.h>
|
||||||
|
|
||||||
class ProjectSurfacePointsOnPoly : public vtkUnstructuredGridAlgorithm {
|
class ProjectSurfacePointsOnPoly : public vtkUnstructuredGridAlgorithm {
|
||||||
public:
|
public:
|
||||||
@ -17,9 +20,20 @@ public:
|
|||||||
vtkSetMacro(affectedNeighborsCount, int);
|
vtkSetMacro(affectedNeighborsCount, int);
|
||||||
vtkGetMacro(affectedNeighborsCount, int);
|
vtkGetMacro(affectedNeighborsCount, int);
|
||||||
|
|
||||||
|
vtkSetMacro(RadiusScale, double);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int affectedNeighborsCount = 0;
|
int affectedNeighborsCount = 0;
|
||||||
|
double RadiusScale;
|
||||||
~ProjectSurfacePointsOnPoly() override = default;
|
~ProjectSurfacePointsOnPoly() override = default;
|
||||||
|
|
||||||
|
void moveSurfacePoint(vtkUnstructuredGrid *tetMesh,
|
||||||
|
vtkPolyData *polyMesh,
|
||||||
|
vtkIdType pointId,
|
||||||
|
std::vector<double> &motionVectors,
|
||||||
|
std::vector<unsigned> &numberOfAffectors,
|
||||||
|
vtkKdTree *kdTree,
|
||||||
|
vtkStaticCellLinks *links);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,13 +30,21 @@ vtkTypeBool RelaxationFilter::RequestData(
|
|||||||
std::set<vtkIdType> neighbors;
|
std::set<vtkIdType> neighbors;
|
||||||
output->BuildLinks();
|
output->BuildLinks();
|
||||||
double avg[3];
|
double avg[3];
|
||||||
|
|
||||||
for (vtkIdType i = 0; i < output->GetNumberOfPoints(); i++) {
|
for (vtkIdType i = 0; i < output->GetNumberOfPoints(); i++) {
|
||||||
|
if (!isSurface->GetValue(i)) continue;
|
||||||
|
|
||||||
output->GetPointCells(i, neighborCells);
|
output->GetPointCells(i, neighborCells);
|
||||||
|
|
||||||
if (neighborCells->GetNumberOfIds() != 0) {
|
if (neighborCells->GetNumberOfIds() != 0) {
|
||||||
|
|
||||||
for (vtkIdType j = 0; j < neighborCells->GetNumberOfIds(); j++) {
|
for (vtkIdType j = 0; j < neighborCells->GetNumberOfIds(); j++) {
|
||||||
|
|
||||||
vtkIdType cellId = neighborCells->GetId(j);
|
vtkIdType cellId = neighborCells->GetId(j);
|
||||||
output->GetCellPoints(cellId, cellPoints);
|
output->GetCellPoints(cellId, cellPoints);
|
||||||
|
|
||||||
for (vtkIdType k = 0; k < cellPoints->GetNumberOfIds(); k++) {
|
for (vtkIdType k = 0; k < cellPoints->GetNumberOfIds(); k++) {
|
||||||
|
|
||||||
vtkIdType neighborId = cellPoints->GetId(k);
|
vtkIdType neighborId = cellPoints->GetId(k);
|
||||||
if (isSurface->GetValue(neighborId)) {
|
if (isSurface->GetValue(neighborId)) {
|
||||||
neighbors.insert(neighborId);
|
neighbors.insert(neighborId);
|
||||||
@ -44,7 +52,10 @@ vtkTypeBool RelaxationFilter::RequestData(
|
|||||||
}
|
}
|
||||||
cellPoints->Reset();
|
cellPoints->Reset();
|
||||||
}
|
}
|
||||||
neighbors.erase(neighbors.find(i));
|
|
||||||
|
if (neighbors.find(i) != neighbors.end()) {
|
||||||
|
neighbors.erase(neighbors.find(i));
|
||||||
|
}
|
||||||
if (neighbors.size() != 0) {
|
if (neighbors.size() != 0) {
|
||||||
avg[0] = 0; avg[1] = 0; avg[2] = 0;
|
avg[0] = 0; avg[1] = 0; avg[2] = 0;
|
||||||
for (const vtkIdType &j : neighbors) {
|
for (const vtkIdType &j : neighbors) {
|
||||||
@ -59,6 +70,7 @@ vtkTypeBool RelaxationFilter::RequestData(
|
|||||||
neighborCells->Reset();
|
neighborCells->Reset();
|
||||||
neighbors.clear();
|
neighbors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
output->SetPoints(newPoints);
|
output->SetPoints(newPoints);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user