Skip to content
Snippets Groups Projects
Commit 87b725f9 authored by Ali Can Demiralp's avatar Ali Can Demiralp
Browse files

Custom transfer function support.

parent aef1704e
Branches
No related tags found
No related merge requests found
...@@ -40,6 +40,7 @@ struct settings ...@@ -40,6 +40,7 @@ struct settings
if (iteratee.isMember("volume" )) entry.volume = iteratee["volume" ].asString(); if (iteratee.isMember("volume" )) entry.volume = iteratee["volume" ].asString();
} }
transfer_function = root["transfer_function"] .asString();
time_scale = root["time_scale" ] .asFloat (); time_scale = root["time_scale" ] .asFloat ();
loop = root["loop" ] .asBool (); loop = root["loop" ] .asBool ();
image_size = {root["image_size" ][0].asUInt (), image_size = {root["image_size" ][0].asUInt (),
...@@ -73,6 +74,7 @@ struct settings ...@@ -73,6 +74,7 @@ struct settings
// Input settings. // Input settings.
std::vector<data_filepath> data_filepaths = {}; std::vector<data_filepath> data_filepaths = {};
std::string transfer_function = "";
float time_scale = 1000.0f; float time_scale = 1000.0f;
bool loop = true; bool loop = true;
......
#ifndef TRANSFER_FUNCTION_HPP
#define TRANSFER_FUNCTION_HPP
#include <cstdint>
#include <fstream>
#include <string>
#include <vtk_jsoncpp.h>
#include <vtkColorTransferFunction.h>
#include <vtkPiecewiseFunction.h>
#include <vtkSmartPointer.h>
namespace rt
{
class transfer_function
{
public:
explicit transfer_function (const std::string& filepath)
{
std::ifstream file_stream(filepath);
vtkJson::Reader reader;
vtkJson::Value root;
reader.parse(file_stream, root);
auto& opacity = root[0]["Points" ];
auto& color = root[0]["RGBPoints"];
auto space = root[0]["ColorSpace"].asString();
for (auto i = 0; i < opacity.size(); i += 4)
opacity_function->AddPoint(
opacity[i ].asFloat(),
opacity[i + 1].asFloat());
for (auto i = 0; i < color.size(); i += 4)
color_function->AddRGBPoint(
color [i ].asFloat(),
color [i + 1].asFloat(),
color [i + 2].asFloat(),
color [i + 3].asFloat());
if (space == "RGB")
color_function->SetColorSpace(VTK_CTF_RGB);
else if (space == "HSV")
color_function->SetColorSpace(VTK_CTF_HSV);
else if (space == "LAB")
color_function->SetColorSpace(VTK_CTF_LAB);
else if (space == "CIEDE2000")
color_function->SetColorSpace(VTK_CTF_LAB_CIEDE2000);
else if (space == "Diverging")
color_function->SetColorSpace(VTK_CTF_DIVERGING);
else if (space == "Step")
color_function->SetColorSpace(VTK_CTF_STEP);
}
transfer_function (const transfer_function& that) = default;
transfer_function ( transfer_function&& temp) = default;
~transfer_function () = default;
transfer_function& operator=(const transfer_function& that) = default;
transfer_function& operator=( transfer_function&& temp) = default;
vtkSmartPointer<vtkPiecewiseFunction> opacity_function = vtkSmartPointer<vtkPiecewiseFunction> ::New();
vtkSmartPointer<vtkColorTransferFunction> color_function = vtkSmartPointer<vtkColorTransferFunction>::New();
};
}
#endif
...@@ -4,24 +4,29 @@ ...@@ -4,24 +4,29 @@
#include <vtkActor.h> #include <vtkActor.h>
#include <vtkCamera.h> #include <vtkCamera.h>
#include <vtkCameraInterpolator.h> #include <vtkCameraInterpolator.h>
#include <vtkColorTransferFunction.h>
#include <vtkOggTheoraWriter.h> #include <vtkOggTheoraWriter.h>
#include <vtkOSPRayPass.h> #include <vtkOSPRayPass.h>
#include <vtkPiecewiseFunction.h>
#include <vtkPolyDataMapper.h> #include <vtkPolyDataMapper.h>
#include <vtkRenderer.h> #include <vtkRenderer.h>
#include <vtkRenderWindow.h> #include <vtkRenderWindow.h>
#include <vtkSmartPointer.h> #include <vtkSmartPointer.h>
#include <vtkUnstructuredGridVolumeRayCastMapper.h> #include <vtkUnstructuredGridVolumeRayCastMapper.h>
#include <vtkVolume.h> #include <vtkVolume.h>
#include <vtkVolumeProperty.h>
#include <vtkWindowToImageFilter.h> #include <vtkWindowToImageFilter.h>
#include <poly_data_io.hpp> #include <poly_data_io.hpp>
#include <settings.hpp> #include <settings.hpp>
#include <transfer_function.hpp>
#include <unstructured_grid_io.hpp> #include <unstructured_grid_io.hpp>
std::int32_t main(std::int32_t argc, char** argv) std::int32_t main(std::int32_t argc, char** argv)
{ {
std::cout << "Parsing settings.\n"; std::cout << "Parsing settings.\n";
auto settings = rt::settings(argv[1]); auto settings = rt::settings(argv[1]);
auto transfer_function = rt::transfer_function(settings.transfer_function);
std::cout << "Setting up renderer.\n"; std::cout << "Setting up renderer.\n";
auto renderer = vtkSmartPointer<vtkRenderer> ::New(); auto renderer = vtkSmartPointer<vtkRenderer> ::New();
...@@ -55,7 +60,9 @@ std::int32_t main(std::int32_t argc, char** argv) ...@@ -55,7 +60,9 @@ std::int32_t main(std::int32_t argc, char** argv)
pd_actor ->SetMapper (pd_mapper); pd_actor ->SetMapper (pd_mapper);
ug_volume->SetMapper (ug_mapper); ug_volume->SetMapper (ug_mapper);
renderer ->AddActor (pd_actor ); renderer ->AddActor (pd_actor );
//renderer ->AddVolume(ug_volume); renderer ->AddVolume (ug_volume);
ug_volume->GetProperty()->SetScalarOpacity(transfer_function.opacity_function);
ug_volume->GetProperty()->SetColor (transfer_function.color_function );
std::cout << "Setting up video writer.\n"; std::cout << "Setting up video writer.\n";
auto window_to_image = vtkSmartPointer<vtkWindowToImageFilter>::New(); auto window_to_image = vtkSmartPointer<vtkWindowToImageFilter>::New();
...@@ -79,7 +86,7 @@ std::int32_t main(std::int32_t argc, char** argv) ...@@ -79,7 +86,7 @@ std::int32_t main(std::int32_t argc, char** argv)
std::cout << "Loading slice " << slice << ".\n"; std::cout << "Loading slice " << slice << ".\n";
last_slice = slice; last_slice = slice;
pd_mapper->SetInputData(rt::poly_data_io ::read(settings.data_filepaths[slice].geometry)); pd_mapper->SetInputData(rt::poly_data_io ::read(settings.data_filepaths[slice].geometry));
//ug_mapper->SetInputData(rt::unstructured_grid_io::read(settings.data_filepaths[slice].volume )); ug_mapper->SetInputData(rt::unstructured_grid_io::read(settings.data_filepaths[slice].volume ));
} }
std::cout << "Rendering frame " << current_time << ".\n"; std::cout << "Rendering frame " << current_time << ".\n";
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
{ "geometry": "/hpcwork/rwth0432/data/oxyflame/GEOM_0013200.vtp", "volume": "/hpcwork/rwth0432/data/oxyflame/QOUT_0013200.vtu" }, { "geometry": "/hpcwork/rwth0432/data/oxyflame/GEOM_0013200.vtp", "volume": "/hpcwork/rwth0432/data/oxyflame/QOUT_0013200.vtu" },
{ "geometry": "/hpcwork/rwth0432/data/oxyflame/GEOM_0013200.vtp", "volume": "/hpcwork/rwth0432/data/oxyflame/QOUT_0013200.vtu" } { "geometry": "/hpcwork/rwth0432/data/oxyflame/GEOM_0013200.vtp", "volume": "/hpcwork/rwth0432/data/oxyflame/QOUT_0013200.vtu" }
], ],
"transfer_function": "/hpcwork/rwth0432/data/oxyflame/transfer_function.json",
"time_scale" : 1000.0, "time_scale" : 1000.0,
"loop" : true, "loop" : true,
......
[
{
"ColorSpace" : "Diverging",
"Name" : "Basic",
"Points" :
[
200.0,
0.0,
0.5,
0.0,
287.01351928710938,
1.0,
0.5,
0.0
],
"RGBPoints" :
[
200.0,
0.231373,
0.298039,
0.75294099999999997,
243.50675964355469,
0.86500299999999997,
0.86500299999999997,
0.86500299999999997,
287.01351928710938,
0.70588200000000001,
0.0156863,
0.14902000000000001
]
}
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment