Created
January 27, 2021 06:37
-
-
Save maz-1/293eb414246b04834329e3da3a2f0533 to your computer and use it in GitHub Desktop.
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
const float resize_ratio = 2.0; | |
actorDroneMesh = vtkSmartPointer<vtkLODActor>::New (); | |
auto sharedData = SharedData::getSharedData(this->window()); | |
OpenMesh::PolyMesh_ArrayKernelT< > mesh_out; | |
OpenMesh::IO::Options OptionRead(OpenMesh::IO::Options::Binary); | |
QFile file_model(":/models/drone.stl"); | |
file_model.open(QIODevice::ReadOnly); | |
QStdIStream drone_model_data(&file_model); | |
OpenMesh::IO::read_mesh(mesh_out, drone_model_data, "stl", OptionRead); | |
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New (); | |
vtkIdType nr_points = mesh_out.n_vertices(); | |
points->SetNumberOfPoints (nr_points); | |
float *data = static_cast<vtkFloatArray*> (points->GetData ())->GetPointer (0); | |
vtkIdType ptr = 0; | |
BOOST_FOREACH(auto v, mesh_out.vertices()) { | |
auto point = mesh_out.point(v); | |
//std::copy (&(point[0]), &(point[0]) + 3, &data[ptr]); | |
data[ptr] = point[0] * resize_ratio; | |
data[ptr + 1] = point[1] * resize_ratio; | |
data[ptr + 2] = point[2] * resize_ratio; | |
ptr += 3; | |
} | |
vtkSmartPointer<vtkCellArray> cell_array = vtkSmartPointer<vtkCellArray>::New (); | |
vtkIdType *cell = cell_array->WritePointer (mesh_out.n_faces(), mesh_out.n_faces() * 4); | |
int idx = 0; | |
BOOST_FOREACH(auto f, mesh_out.faces()) { | |
*cell++ = 3; | |
for (auto fv_it = mesh_out.fv_iter(f); fv_it.is_valid(); ++fv_it, ++idx) { | |
*cell++ = (*fv_it).idx(); | |
} | |
++idx; | |
} | |
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New (); | |
cell_array->GetData ()->SetNumberOfValues (idx); | |
cell_array->Squeeze (); | |
polydata->SetPolys (cell_array); | |
polydata->SetPoints (points); | |
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New (); | |
mapper->SetInputData (polydata); | |
actorDroneMesh->SetNumberOfCloudPoints (int (std::max<vtkIdType> (1, polydata->GetNumberOfPoints () / 10))); | |
actorDroneMesh->GetProperty ()->SetInterpolationToFlat (); | |
actorDroneMesh->SetMapper (mapper); | |
actorDroneMesh->GetProperty ()->SetRepresentationToSurface (); | |
// Backface culling renders the visualization slower, but guarantees that we see all triangles | |
actorDroneMesh->GetProperty ()->BackfaceCullingOff (); | |
actorDroneMesh->GetProperty ()->SetInterpolationToFlat (); | |
actorDroneMesh->GetProperty ()->EdgeVisibilityOff (); | |
actorDroneMesh->GetProperty ()->ShadingOff (); | |
//renderer->AddActor(actorDroneMesh); | |
file_model.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment