Skip to content

Commit b28f1c3

Browse files
committed
Clean up--works on Mac
1 parent 696f147 commit b28f1c3

File tree

1 file changed

+19
-71
lines changed

1 file changed

+19
-71
lines changed

src/Modules/Visualization/Tests/OsprayFieldRenderTests.cc

Lines changed: 19 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -108,51 +108,20 @@ namespace osprayImpl
108108
std::cout << "wrote file " << fileName << std::endl;
109109
}
110110

111-
template <typename T>
112-
std::string join(const T& list)
113-
{
114-
std::ostringstream oss;
115-
const auto SIZE = list.size();
116-
for (int i = 0; i < SIZE; ++i)
117-
{
118-
oss << list[i];
119-
if (i < SIZE - 1)
120-
oss << ", ";
121-
}
122-
return oss.str();
123-
}
124-
125-
int renderLatVol(FieldHandle latvol, float cameraSteps)
111+
int renderLatVol(FieldHandle latvol, float cameraSteps, int max)
126112
{
127113
FieldHandle trisurf;
128-
//if (false)
129114
{
130115
GetFieldBoundaryAlgo getfieldbound_algo;
131116
FieldHandle field_boundary;
132117
getfieldbound_algo.run(latvol, field_boundary);
133118
ConvertMeshToTriSurfMeshAlgo converter;
134-
119+
135120
converter.run(field_boundary, trisurf);
136121
}
137122

138-
//trisurf = TriangleTriSurfLinearBasis(DOUBLE_E);
139123
auto facade(trisurf->mesh()->getFacade());
140124

141-
//std::ostringstream ostr;
142-
//for (const auto& node : facade->nodes())
143-
//{
144-
// auto edges = node.edgeIndices();
145-
// ostr << "Node " << node.index() << " point=" << node.point().get_string() << /*" edges=[" << join(edges) << "]" <<*/ std::endl;
146-
//}
147-
//for (const auto& face : facade->faces())
148-
//{
149-
// auto faceID = face.index();
150-
// auto nodes = face.nodeIndices();
151-
// ostr << "Face " << faceID << " nodes=[" << join(nodes) << "]" << std::endl;
152-
//}
153-
154-
//std::cout << ostr.str() << std::endl;
155-
156125
std::cout << "hello ospray" << std::endl;
157126
// image size
158127
osp::vec2i imgSize;
@@ -164,47 +133,36 @@ namespace osprayImpl
164133
cam_pos[0] += cameraSteps;
165134
float cam_up[] = { 0.f, 1.f, 0.f };
166135
float cam_view[] = { 0.5f, 0.5f, 1.f };
167-
//cam_view[2] += cam_pos[2];
168136

169137
// triangle mesh data
170-
float vertex_example[] = { -1.0f, -1.0f, 3.0f, 0.f,
171-
-1.0f, 1.0f, 3.0f, 0.f,
172-
1.0f, -1.0f, 3.0f, 0.f,
173-
0.1f, 0.1f, 0.3f, 0.f };
138+
// float vertex_example[] = { -1.0f, -1.0f, 3.0f, 0.f,
139+
// -1.0f, 1.0f, 3.0f, 0.f,
140+
// 1.0f, -1.0f, 3.0f, 0.f,
141+
// 0.1f, 0.1f, 0.3f, 0.f };
174142

175143
std::vector<float> vertex, color;
144+
float maxColor = max;
176145
{
177-
//auto i = 0;
178146
for (const auto& node : facade->nodes())
179147
{
180148
auto point = node.point();
181149
vertex.push_back(static_cast<float>(point.x()));
182150
vertex.push_back(static_cast<float>(point.y()));
183151
vertex.push_back(static_cast<float>(point.z()));
184152
vertex.push_back(0);
185-
//++i;
186-
//if (i % 2 == 0)
187-
{
188-
color.push_back(0.9f);
189-
color.push_back(0.5f);
190-
color.push_back(0.5f);
191-
}
192-
//else
193-
//{
194-
// color.push_back(0.8f);
195-
// color.push_back(0.8f);
196-
// color.push_back(0.8f);
197-
//}
153+
color.push_back(0.9f * point.x() / maxColor);
154+
color.push_back(0.9f * point.y() / maxColor);
155+
color.push_back(0.9f * point.z() / maxColor);
198156
color.push_back(1.0f);
199157
}
200158
}
201159

202-
float color_example[] = { 0.9f, 0.5f, 0.5f, 1.0f,
203-
0.8f, 0.8f, 0.8f, 1.0f,
204-
0.8f, 0.8f, 0.8f, 1.0f,
205-
0.5f, 0.9f, 0.5f, 1.0f };
206-
int32_t index_example[] = { 0, 1, 2,
207-
1, 2, 3};
160+
// float color_example[] = { 0.9f, 0.5f, 0.5f, 1.0f,
161+
// 0.8f, 0.8f, 0.8f, 1.0f,
162+
// 0.8f, 0.8f, 0.8f, 1.0f,
163+
// 0.5f, 0.9f, 0.5f, 1.0f };
164+
// int32_t index_example[] = { 0, 1, 2,
165+
// 1, 2, 3};
208166

209167
std::vector<int32_t> index;
210168
{
@@ -217,9 +175,6 @@ namespace osprayImpl
217175
}
218176
}
219177

220-
221-
222-
223178
// create and setup camera
224179
OSPCamera camera = ospNewCamera("perspective");
225180
ospSetf(camera, "aspect", imgSize.x / (float)imgSize.y);
@@ -228,7 +183,6 @@ namespace osprayImpl
228183
ospSet3fv(camera, "up", cam_up);
229184
ospCommit(camera); // commit each object to indicate modifications are done
230185

231-
232186
// create and setup model and mesh
233187
OSPGeometry mesh = ospNewGeometry("triangles");
234188
OSPData data = ospNewData(vertex.size() / 4, OSP_FLOAT3A, &vertex[0]); // OSP_FLOAT3 format is also supported for vertex positions
@@ -248,7 +202,6 @@ namespace osprayImpl
248202

249203
ospCommit(mesh);
250204

251-
252205
OSPModel world = ospNewModel();
253206
ospAddGeometry(world, mesh);
254207
ospCommit(world);
@@ -270,7 +223,6 @@ namespace osprayImpl
270223
ospSetObject(renderer, "lights", lights);
271224
ospCommit(renderer);
272225

273-
274226
// create and setup framebuffer
275227
OSPFrameBuffer framebuffer = ospNewFrameBuffer(imgSize, OSP_FB_SRGBA, OSP_FB_COLOR | /*OSP_FB_DEPTH |*/ OSP_FB_ACCUM);
276228
ospFrameBufferClear(framebuffer, OSP_FB_COLOR | OSP_FB_ACCUM);
@@ -280,19 +232,15 @@ namespace osprayImpl
280232

281233
// access framebuffer and write its content as PPM file
282234
const uint32_t * fb = (uint32_t*)ospMapFrameBuffer(framebuffer, OSP_FB_COLOR);
283-
//std::ostringstream fileName;
284-
//fileName << "firstFrame" << cameraSteps << ".ppm";
285-
//writePPM(fileName.str().c_str(), imgSize, fb);
286235
ospUnmapFrameBuffer(fb, framebuffer);
287236

288-
289237
// render 10 more frames, which are accumulated to result in a better converged image
290238
for (int frames = 0; frames < 10; frames++)
291239
ospRenderFrame(framebuffer, renderer, OSP_FB_COLOR | OSP_FB_ACCUM);
292240

293241
fb = (uint32_t*)ospMapFrameBuffer(framebuffer, OSP_FB_COLOR);
294242
std::ostringstream fileNameAcc;
295-
fileNameAcc << "accumulatedFrame" << cameraSteps << ".ppm";
243+
fileNameAcc << "accumulatedFrame_" << vertex.size() << "_" << cameraSteps << ".ppm";
296244
writePPM(fileNameAcc.str().c_str(), imgSize, fb);
297245
ospUnmapFrameBuffer(fb, framebuffer);
298246

@@ -304,10 +252,10 @@ namespace osprayImpl
304252
TEST_P(OsprayFieldRenderTest, RenderLatVolWithOspray)
305253
{
306254
Log::get() << INFO << "Start ShowField::execute" << std::endl;
307-
255+
308256
for (int inc : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
309257
{
310-
osprayImpl::renderLatVol(latVol, inc*0.2);
258+
osprayImpl::renderLatVol(latVol, inc*0.2, GetParam());
311259
}
312260

313261
FAIL() << "todo";

0 commit comments

Comments
 (0)