Skip to content

Commit b9a2088

Browse files
committed
Set up WITH_OSPRAY build flag
1 parent 7a81841 commit b9a2088

File tree

5 files changed

+44
-13
lines changed

5 files changed

+44
-13
lines changed

Superbuild/Superbuild.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ OPTION(BUILD_WITH_PYTHON "Build with python support." ON)
7474
# Configure tetgen
7575
OPTION(WITH_TETGEN "Build Tetgen." OFF)
7676

77+
78+
###########################################
79+
# Configure ospray -- TODO: convert into real external
80+
OPTION(WITH_OSPRAY "Build with Ospray support." OFF)
81+
7782
###########################################
7883
# Configure data
7984
OPTION(BUILD_WITH_SCIRUN_DATA "Svn checkout data" OFF)

src/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,13 @@ IF(WITH_TETGEN)
364364
ADD_DEFINITIONS(-DWITH_TETGEN)
365365
ENDIF()
366366

367+
########################################################################
368+
# Configure ospray module build
369+
370+
IF(WITH_OSPRAY)
371+
ADD_DEFINITIONS(-DWITH_OSPRAY)
372+
ENDIF()
373+
367374
########################################################################
368375
# Copy Spire-SCIRun specific assets and shaders
369376

@@ -717,7 +724,7 @@ SET_PROPERTY(TARGET Testing_Utils PROPERTY FOLDER "Testing Support")
717724
SET_PROPERTY(TARGET Testing_ModuleTestBase PROPERTY FOLDER "Testing Support")
718725

719726
IF(BUILD_TESTING)
720-
727+
721728
#SET_PROPERTY(TARGET SCIRunTestData_external PROPERTY FOLDER "Testing Support")
722729

723730
SET_PROPERTY(TARGET Algorithms_Base_Tests PROPERTY FOLDER "Core/Algorithms/Tests")

src/Modules/Visualization/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ SCIRUN_ADD_LIBRARY(Modules_Visualization
5454
${Modules_Visualization_SRCS}
5555
)
5656

57-
INCLUDE(${CMAKE_SOURCE_DIR}/CMake/Modules/FindOSPRay.cmake)
58-
59-
INCLUDE_DIRECTORIES(${OSPRAY_INCLUDE_DIRS})
60-
6157
TARGET_LINK_LIBRARIES(Modules_Visualization
6258
Dataflow_Network
6359
Core_Datatypes
@@ -67,9 +63,14 @@ TARGET_LINK_LIBRARIES(Modules_Visualization
6763
Graphics_Glyphs
6864
Graphics_Datatypes
6965
${SCI_FREETYPE_LIBRARY}
70-
${OSPRAY_LIBRARIES}
7166
)
7267

68+
IF(WITH_OSPRAY)
69+
INCLUDE(${CMAKE_SOURCE_DIR}/CMake/Modules/FindOSPRay.cmake)
70+
INCLUDE_DIRECTORIES(${OSPRAY_INCLUDE_DIRS})
71+
TARGET_LINK_LIBRARIES(Modules_Visualization ${OSPRAY_LIBRARIES})
72+
ENDIF()
73+
7374
IF(BUILD_SHARED_LIBS)
7475
ADD_DEFINITIONS(-DBUILD_Modules_Visualization)
7576
ENDIF(BUILD_SHARED_LIBS)

src/Modules/Visualization/InterfaceWithOspray.cc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ DEALINGS IN THE SOFTWARE.
3838

3939
#include <boost/date_time/posix_time/posix_time.hpp>
4040

41+
#ifdef WITH_OSPRAY
4142
#include <ospray/ospray.h>
43+
#endif
4244

4345
using namespace SCIRun;
4446
using namespace Dataflow::Networks;
@@ -96,6 +98,7 @@ void InterfaceWithOspray::setStateDefaults()
9698

9799
namespace detail
98100
{
101+
#ifdef WITH_OSPRAY
99102
class OsprayImpl
100103
{
101104
public:
@@ -114,7 +117,7 @@ namespace detail
114117

115118
// image size
116119
osp::vec2i imgSize;
117-
imgSize.x = state->getValue(Parameters::ImageWidth).toInt();
120+
imgSize.x = state->getValue(Parameters::ImageWidth).toInt();
118121
imgSize.y = state->getValue(Parameters::ImageHeight).toInt();
119122

120123
auto toFloat = [state](const Name& name) { return static_cast<float>(state->getValue(name).toDouble()); };
@@ -203,7 +206,7 @@ namespace detail
203206
// complete setup of renderer
204207
ospSet1i(renderer, "aoSamples", 1);
205208
ospSet3f(renderer, "bgColor", toFloat(Parameters::BackgroundColorR),
206-
toFloat(Parameters::BackgroundColorG),
209+
toFloat(Parameters::BackgroundColorG),
207210
toFloat(Parameters::BackgroundColorB));
208211
ospSetObject(renderer, "model", world);
209212
ospSetObject(renderer, "camera", camera);
@@ -233,10 +236,10 @@ namespace detail
233236
FILE *file = fopen(fileName, "wb");
234237
fprintf(file, "P6\n%i %i\n255\n", size.x, size.y);
235238
std::vector<unsigned char> out(3 * size.x);
236-
for (int y = 0; y < size.y; y++)
239+
for (int y = 0; y < size.y; y++)
237240
{
238241
const unsigned char *in = (const unsigned char *)&pixel[(size.y - 1 - y)*size.x];
239-
for (int x = 0; x < size.x; x++)
242+
for (int x = 0; x < size.x; x++)
240243
{
241244
out[3 * x + 0] = in[4 * x + 0];
242245
out[3 * x + 1] = in[4 * x + 1];
@@ -249,6 +252,9 @@ namespace detail
249252
std::cout << "wrote file " << fileName << std::endl;
250253
}
251254
};
255+
#else
256+
class OsprayImpl {};
257+
#endif
252258
}
253259

254260
InterfaceWithOspray::InterfaceWithOspray() : GeometryGeneratingModule(staticInfo_), impl_(new detail::OsprayImpl)
@@ -260,6 +266,7 @@ InterfaceWithOspray::InterfaceWithOspray() : GeometryGeneratingModule(staticInfo
260266

261267
void InterfaceWithOspray::execute()
262268
{
269+
#ifdef WITH_OSPRAY
263270
auto field = getRequiredInput(Field);
264271
auto colorMap = getOptionalInput(ColorMapObject);
265272

@@ -275,8 +282,11 @@ void InterfaceWithOspray::execute()
275282
remark("Saving output to " + filename);
276283
impl_->writeImage(field, filename, get_state(), colorMap);
277284
get_state()->setTransientValue(Variables::Filename, filename);
278-
285+
279286
//auto geom = builder_->buildGeometryObject(field, colorMap, *this, this);
280287
//sendOutput(SceneGraph, geom);
281288
}
289+
#else
290+
error("Build SCIRun with WITH_OSPRAY set to true to enable this module.");
291+
#endif
282292
}

src/Modules/Visualization/Tests/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ SET(Modules_Visualization_Tests_SRCS
3434
ShowFieldTests.cc
3535
ShowMeshTests.cc
3636
ShowStringTests.cc
37-
OsprayFieldRenderTests.cc
3837
)
3938

39+
IF(WITH_OSPRAY)
40+
SET(Modules_Visualization_Tests_SRCS ${Modules_Visualization_Tests_SRCS}
41+
OsprayFieldRenderTests.cc
42+
)
43+
ENDIF()
44+
4045
SCIRUN_ADD_UNIT_TEST(Modules_Visualization_Tests
4146
${Modules_Visualization_Tests_SRCS}
4247
)
@@ -53,5 +58,8 @@ TARGET_LINK_LIBRARIES(Modules_Visualization_Tests
5358
gtest_main
5459
gtest
5560
gmock
56-
${OSPRAY_LIBRARIES}
5761
)
62+
63+
IF(WITH_OSPRAY)
64+
TARGET_LINK_LIBRARIES(Modules_Visualization_Tests ${OSPRAY_LIBRARIES})
65+
ENDIF()

0 commit comments

Comments
 (0)