-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.h
67 lines (55 loc) · 2.27 KB
/
render.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <vtkActor.h>
#include <vtkInteractorStyleSwitch.h>
#include <vtkPNGWriter.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSphereSource.h>
#include <vtkSTLWriter.h>
#include <vtkTransform.h>
#include <vtkTransformFilter.h>
#include <vtkWindowToImageFilter.h>
inline void Render(vtkSmartPointer<vtkAlgorithm> shape, const char* output) {
auto stl_writer = vtkSmartPointer<vtkSTLWriter>::New();
std::string stl_filename(output);
stl_filename.append(".stl");
stl_writer->SetFileName(stl_filename.c_str());
stl_writer->SetInputConnection(shape->GetOutputPort());
stl_writer->Write();
std::cout << "Wrote to " << stl_filename << std::endl;
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(shape->GetOutputPort());
mapper->SetScalarModeToUseCellFieldData();
mapper->SelectColorArray("vtkApplyColors color");
mapper->SetScalarVisibility(true);
auto actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(0.8, 1, 0.8);
auto renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddViewProp(actor);
auto render_window = vtkSmartPointer<vtkRenderWindow>::New();
render_window->AddRenderer(renderer);
auto interator = vtkSmartPointer<vtkRenderWindowInteractor>::New();
interator->SetRenderWindow(render_window);
auto interactor_style = vtkSmartPointer<vtkInteractorStyleSwitch>::New();
interactor_style->SetCurrentStyleToTrackballCamera();
interator->SetInteractorStyle(interactor_style);
render_window->Render();
auto screenshot_filter = vtkSmartPointer<vtkWindowToImageFilter>::New();
screenshot_filter->SetInput(render_window);
screenshot_filter->SetScale(1, 1);
screenshot_filter->SetInputBufferTypeToRGBA();
screenshot_filter->ReadFrontBufferOff();
auto png_writer = vtkSmartPointer<vtkPNGWriter>::New();
std::string png_filename(output);
png_filename.append(".png");
png_writer->SetFileName(png_filename.c_str());
png_writer->SetInputConnection(screenshot_filter->GetOutputPort());
png_writer->Write();
std::cout << "Wrote to " << png_filename << std::endl;
render_window->Render();
interator->Start();
}