3 #include <vtkSmartPointer.h>
4 #include <vtkPolyData.h>
5 #include <vtkCellArray.h>
8 #include <vtkTriangle.h>
9 #include <vtkProperty.h>
10 #include <vtkImageData.h>
11 #include <vtkTexture.h>
12 #include <vtkFloatArray.h>
13 #include <vtkPointData.h>
14 #include <vtkCellData.h>
18 #include <vtkPolyDataMapper.h>
39 std::unique_lock<std::mutex> l(
mutex);
71 for(
auto& index : visible_indices)
83 if(old_highRes.find(it.first) != old_highRes.end())
85 m_highRes.at(it.first) = old_highRes.at(it.first);
99 typedef std::pair<float, size_t> IndexPair;
100 typedef std::pair<float, BaseVector<float> > CentroidPair;
113 if(index_queue.size() < numCopy)
118 else if(index_queue.top().first > distance)
122 centroid_queue.pop();
132 for(
size_t i = 0; i < visible_indices.size(); ++i)
140 while(!index_queue.empty())
142 size_t index = index_queue.top().second;
146 m_highRes.insert({index, old_highRes[index]});
148 auto centroid = centroid_queue.top().second;
149 centroid_queue.pop();
155 std::unordered_map<size_t, vtkSmartPointer<vtkActor>> tmp_highResActors;
159 size_t id = chunk.first;
175 for(
auto& it: visible_indices)
177 if(tmp_highResActors.find(it) == tmp_highResActors.end())
189 if(tmp_highResActors.find(it.first) == tmp_highResActors.end())
193 remove_actors.insert({it.first, it.second});
197 for(
auto& it: tmp_highResActors)
203 new_actors.insert({it.first, it.second});
221 std::vector<size_t> indices,
225 std::unique_lock<std::mutex> l(
mutex);
237 std::cout <<
"Generating actors " << std::endl;
242 renderer->AddActor(bbridge.
getActor());
245 auto min = bb.getLongestSide();
251 Vector3d focal_point(centroid[0], centroid[1], centroid[2]);
253 renderer->GetActiveCamera()->SetPosition(cam_origin.x(), cam_origin.y(), cam_origin.z());
254 renderer->GetActiveCamera()->SetFocalPoint(focal_point.x(), focal_point.y(), focal_point.z());
255 renderer->GetActiveCamera()->SetViewUp(view_up.x(), view_up.y(), view_up.z());
270 std::vector<size_t> hashes;
274 std::vector<BaseVector<float> > centroids;
277 hashes.push_back(chunk.first);
278 FloatChannel vertices = *(chunk.second->getFloatChannel(
"vertices"));
290 minX = std::min(minX,
p.x);
291 minY = std::min(minY,
p.y);
292 minZ = std::min(minZ,
p.z);
294 maxX = std::max(maxX,
p.x);
295 maxY = std::max(maxY,
p.y);
296 maxZ = std::max(maxZ,
p.z);
306 hashes, centroids, bb);
311 std::cout <<
"Computing actors " << std::endl;
313 std::cout <<
"Adding actors." << std::endl;
316 renderer->AddActor(actor.second);
317 actor.second->VisibilityOff();
319 std::cout <<
"Added " <<
m_chunkActors.size() <<
" actors" << std::endl;
325 std::vector<size_t> & indices)
328 m_oct->intersect(planes, centroids, indices);
339 size_t id = chunk.first;
353 vtkSmartPointer<vtkActor> meshActor = vtkSmartPointer<vtkActor>::New();
357 vtkSmartPointer<vtkPolyData>
mesh = vtkSmartPointer<vtkPolyData>::New();
359 size_t n_v, n_i, n_c;
361 n_v = meshbuffer->numVertices();
362 floatArr vertices = meshbuffer->getVertices();
363 n_i = meshbuffer->numFaces();
364 indexArray indices = meshbuffer->getFaceIndices();
369 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
370 vtkSmartPointer<vtkFloatArray> pts_data = vtkSmartPointer<vtkFloatArray>::New();
371 pts_data->SetNumberOfComponents(3);
372 pts_data->SetVoidArray(meshbuffer->getVertices().get(), n_v * 3, 1);
373 points->SetData(pts_data);
376 vtkSmartPointer<vtkUnsignedCharArray> scalars = vtkSmartPointer<vtkUnsignedCharArray>::New();
377 scalars->SetNumberOfComponents(3);
378 scalars->SetName(
"Colors");
386 vtkSmartPointer<vtkCellArray> triangles = vtkSmartPointer<vtkCellArray>::New();
387 vtkSmartPointer<vtkIdTypeArray> tri_data = vtkSmartPointer<vtkIdTypeArray>::New();
389 vtkIdType* tri_buf =
new vtkIdType[n_i * 4];
390 for(
size_t i = 0; i < n_i; i++)
392 size_t index = 3 * i;
394 tri_buf[i2 + 0] =
static_cast<vtkIdType
>(3);
395 tri_buf[i2 + 1] =
static_cast<vtkIdType
>(indices[index + 0]);
396 tri_buf[i2 + 2] =
static_cast<vtkIdType
>(indices[index + 1]);
397 tri_buf[i2 + 3] =
static_cast<vtkIdType
>(indices[index + 2]);
404 tri_data->SetVoidArray(tri_buf, n_i * 4, 0, vtkIdTypeArray::VTK_DATA_ARRAY_DELETE);
406 triangles->SetCells(n_i, tri_data);
409 mesh->SetPoints(points);
410 mesh->SetPolys(triangles);
413 mesh->GetPointData()->SetScalars(scalars);
416 vtkSmartPointer<vtkPolyDataMapper> mesh_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
419 mesh_mapper->SetInput(
mesh);
421 mesh_mapper->SetInputData(
mesh);
423 meshActor->SetMapper(mesh_mapper);
424 meshActor->GetProperty()->BackfaceCullingOff();
425 vtkSmartPointer<vtkPolyDataMapper> wireframe_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
428 wireframe_mapper->SetInput(
mesh);
430 wireframe_mapper->SetInputData(
mesh);
443 vtkSmartPointer<vtkProperty>
p = meshActor->GetProperty();
444 p->SetColor(0.9, 0.9, 0.9);
445 meshActor->SetProperty(
p);
453 mesh_mapper->Update();