4#include <cgv/utils/file.h>
6#include <cgv/utils/tokenizer.h>
8#pragma warning(disable:4996)
56 std::cerr <<
"Can not add different component types." << std::endl;
63 if(nr_existing_components < 1)
65 std::cerr <<
"Existing data view has no component." << std::endl;
68 if(nr_existing_components > 3)
70 std::cerr <<
"Existing data view already more than 3 components (" << std::to_string(nr_existing_components) <<
"). Cant add to that." << std::endl;
74 if(nr_component_components != 1)
76 std::cerr <<
"New component may only have one component, but has" << std::to_string(nr_component_components) <<
"." << std::endl;
80 unsigned int component_number_of_dimensions = component_format_ptr->
get_nr_dimensions();
81 unsigned int existing_number_of_dimensions = existing_format_ptr->
get_nr_dimensions();
83 if(component_number_of_dimensions < 3 || component_number_of_dimensions > 4 || component_number_of_dimensions != existing_number_of_dimensions)
85 std::cerr <<
"Both data views need to have 3 or 4 dimensions (and both the same number). They have " << std::to_string(existing_number_of_dimensions) <<
" (existing) and" << std::to_string(component_number_of_dimensions) <<
" (new component)." << std::endl;
91 std::cerr <<
"The dimensions do not match: existing (" << std::to_string(existing_format_ptr->
get_width()) <<
", " << std::to_string(existing_format_ptr->
get_height()) <<
", " << std::to_string(existing_format_ptr->
get_depth()) <<
") vs. new component ("<< std::to_string(component_format_ptr->
get_width()) <<
", "<< std::to_string(component_format_ptr->
get_height()) <<
", " << std::to_string(component_format_ptr->
get_depth()) <<
")." << std::endl;
96 switch(nr_existing_components+nr_component_components) {
99 default: result_component_format =
data::CF_RG;
break;
102 size_t w = existing_format_ptr->
get_width();
104 size_t d = existing_format_ptr->
get_depth();
106 if(component_number_of_dimensions == 4)
110 if(component_number_of_dimensions == 4)
121 for (
unsigned x = 0; x < w; ++x) {
122 for (
unsigned y = 0; y < h; ++y) {
123 for (
unsigned z = 0; z < d; ++z) {
124 for (
unsigned i = 0; i < t; ++i) {
126 unsigned char* existing_ptr =
dv.
get_ptr<
unsigned char>(x, y, z , mask_t* i);
127 unsigned char* component_ptr = component_dv.
get_ptr<
unsigned char>(x, y, z, mask_t* i);
128 unsigned char* result_ptr = combined_dv.
get_ptr<
unsigned char>(x, y, z, mask_t* i);
130 const unsigned copy_size = component_size * nr_existing_components;
131 memcpy(result_ptr, existing_ptr, copy_size);
132 memcpy(result_ptr, component_ptr, component_size);
150 std::cerr <<
"Can not replace with different component types." << std::endl;
155 if(nr_components != 1)
157 std::cerr <<
"Replacement component may only have one component, but has" << std::to_string(nr_components) <<
"." << std::endl;
161 unsigned int component_number_of_dimensions = component_format_ptr->
get_nr_dimensions();
163 if(component_number_of_dimensions < 3 || component_number_of_dimensions > 4)
165 std::cerr <<
"The replacement data view needs to have 3 or 4 dimensions, but has " << std::to_string(component_number_of_dimensions) <<
"." << std::endl;
170 std::cerr <<
"The replacement data view needs to have the same number of dimensions, but has " << std::to_string(component_number_of_dimensions) <<
" (existing has "<< std::to_string(
dv.
get_format()->
get_nr_dimensions()) <<
")." << std::endl;
176 std::cerr <<
"The dimensions do not match: existing (" << std::to_string(existing_format_ptr->
get_width()) <<
", " << std::to_string(existing_format_ptr->
get_height()) <<
", " << std::to_string(existing_format_ptr->
get_depth()) <<
") vs. new component ("<< std::to_string(component_format_ptr->
get_width()) <<
", "<< std::to_string(component_format_ptr->
get_height()) <<
", " << std::to_string(component_format_ptr->
get_depth()) <<
")." << std::endl;
180 size_t w = existing_format_ptr->
get_width();
182 size_t d = existing_format_ptr->
get_depth();
184 if(component_number_of_dimensions == 4)
189 if(component_number_of_dimensions == 4)
194 for (
unsigned i = 0; i < t; ++i) {
195 for (
unsigned z = 0; z < d; ++z) {
196 for (
unsigned y = 0; y < h; ++y) {
197 for (
unsigned x = 0; x < w; ++x) {
199 unsigned char* existing_ptr =
dv.
get_ptr<
unsigned char>(x, y, z, mask_t * i);
200 unsigned char* component_ptr = component_dv.
get_ptr<
unsigned char>(x, y, z, mask_t * i);
202 memcpy(existing_ptr, component_ptr, component_size);
215 std::size_t n = dimensions(0);
complete implementation of method actions that only call one method when entering a node
const data_format * get_format() const
return the component format
cgv::type::func::transfer_const< P, S * >::type get_ptr() const
return a data pointer to type S
the data view gives access to a data array of one, two, three or four dimensions.
ComponentFormat
define standard formats, which should be used to avoid wrong assignment of component names
@ CF_RGBA
color format with components R, G and B
@ CF_RGB
color format with two components R and G
@ CF_RG
color format with intensity and alpha components: I and A
unsigned int get_type_size(TypeId tid)
function that returns the size of a type specified through TypeId
TypeId
ids for the different types and type constructs
Helper functions to process strings.