cgv
Loading...
Searching...
No Matches
volume.h
1#pragma once
2
3#include <cgv/math/fvec.h>
4#include <cgv/media/axis_aligned_box.h>
5#include <cgv/data/data_view.h>
6#include <cgv/type/info/type_id.h>
7
8#include "../lib_begin.h"
9
10namespace cgv {
11 namespace media {
12 namespace volume {
13
14 class CGV_API volume
15 {
16 public:
17 typedef float coord_type;
23 protected:
30 public:
32 volume();
34 volume(const volume& V);
36 ~volume() { clear(); }
38 bool empty() const { return get_dimensions() == dimension_type(0, 0, 0); }
42 const cgv::data::data_format& get_format() const { return df; }
45
57 void set_component_format(const std::string& format) { df.set_component_format(cgv::data::component_format(format)); }
59 unsigned get_nr_components() const { return df.get_nr_components(); }
61 unsigned get_component_size() const { return cgv::type::info::get_type_size(get_component_type()); }
63 unsigned get_voxel_size() const { return df.get_component_format().get_entry_size(); }
65 size_t get_row_size() const { return df.get_width() * get_voxel_size(); }
67 size_t get_slice_size() const { return df.get_height() * get_row_size(); }
69 size_t get_size() const { return get_voxel_size() * get_nr_voxels(); }
71
75 virtual dimension_type get_dimensions() const;
77 size_t get_nr_voxels() const;
79 virtual void resize(const dimension_type& S);
81
85 box_type get_box() const;
87 const extent_type& get_extent() const { return extent; }
89 extent_type& ref_extent() { return extent; }
91 extent_type get_spacing() const;
93
97 const cgv::data::data_view& get_data_view() const { return dv; }
101 template <typename T>
102 const T* get_data_ptr() const { return dv.get_ptr<T>(); }
104 template <typename T>
105 T* get_data_ptr() { return dv.get_ptr<T>(); }
107 template <typename T>
108 const T* get_slice_ptr(unsigned k) const { return dv.get_ptr<T>(k); }
110 template <typename T>
111 T* get_slice_ptr(unsigned k) { return dv.get_ptr<T>(k); }
113 template <typename T>
114 const T* get_row_ptr(unsigned j, unsigned k) const { return dv.get_ptr<T>(k, j); }
116 template <typename T>
117 T* get_row_ptr(unsigned j, unsigned k) { return dv.get_ptr<T>(k, j); }
119 template <typename T>
120 const T* get_voxel_ptr(unsigned i, unsigned j, unsigned k) const { return dv.get_ptr<T>(k, j, i); }
122 template <typename T>
123 T* get_voxel_ptr(unsigned i, unsigned j, unsigned k) { return dv.get_ptr<T>(k, j, i); }
125 template <typename T>
126 T get_voxel_component(unsigned i, unsigned j, unsigned k, unsigned ci = 0) { return dv.get<T>(ci, k, j, i); }
128
132 bool add_new_component(data::data_view& component_dv);
134 bool replace_component(unsigned i, data::data_view& component_dv);
136 };
137 }
138 }
139}
140
141#include <cgv/config/lib_end.h>
the component format inherits the information of a packing_info and adds information on the component...
void set_component_type(cgv::type::info::TypeId _type_id)
set the component type
cgv::type::info::TypeId get_component_type() const
return the component type
ComponentFormat get_standard_component_format() const
return whether the component format is one of the standard formats
unsigned int get_entry_size() const
return the size of one entry of components in bytes
unsigned int get_nr_components() const
return the number of components
A data_format describes a multidimensional data block of data entries.
Definition data_format.h:17
void set_component_format(const component_format &cf)
set component_format by simply assigning to a converted this pointer
size_t get_width() const
return the resolution in the first dimension, or 1 if not defined
size_t get_height() const
return the resolution in the second dimension, or 1 if not defined
const component_format & get_component_format() const
return the component_format info by simple conversion of the this pointer
S get(unsigned ci) const
constant access to the ci-th component
Definition data_view.h:86
cgv::type::func::transfer_const< P, S * >::type get_ptr() const
return a data pointer to type S
Definition data_view.h:61
the data view gives access to a data array of one, two, three or four dimensions.
Definition data_view.h:153
A vector with zero based index.
Definition fvec.h:26
An axis aligned box, defined by to points: min and max.
T * get_data_ptr()
return a pointer to the data
Definition volume.h:105
extent_type & ref_extent()
return reference spacing
Definition volume.h:89
T * get_slice_ptr(unsigned k)
return a pointer to the data of the k-th slice
Definition volume.h:111
void set_component_format(const std::string &format)
set the component format from a string according to the syntax declared in <cgv/data/component_format...
Definition volume.h:57
cgv::data::data_format & get_format()
return reference to data format
Definition volume.h:44
const cgv::data::data_format & get_format() const
return const reference to data format
Definition volume.h:42
cgv::data::ComponentFormat get_component_format() const
return component format
Definition volume.h:51
T * get_voxel_ptr(unsigned i, unsigned j, unsigned k)
return a pointer to the component data of voxel (i,j,k)
Definition volume.h:123
extent_type extent
extent of the volume in each coordinate direction
Definition volume.h:29
T * get_row_ptr(unsigned j, unsigned k)
return a pointer to the data of the j-th row in the k-th slice
Definition volume.h:117
cgv::data::data_format df
format description of volume data
Definition volume.h:25
void clear()
deallocate all memory and reset data format to "uint8[L]"
Definition volume.h:40
unsigned get_nr_components() const
return the number of components within a voxel
Definition volume.h:59
cgv::data::data_view dv
data storage of volume data
Definition volume.h:27
const cgv::data::data_view & get_data_view() const
return a const reference to the data view
Definition volume.h:97
const T * get_data_ptr() const
return a const pointer to the data
Definition volume.h:102
size_t get_row_size() const
return the size of a row within a slice in bytes
Definition volume.h:65
void set_component_type(cgv::type::info::TypeId type_id)
set the value type of the voxel components
Definition volume.h:55
const extent_type & get_extent() const
return const reference to spatial extent
Definition volume.h:87
unsigned get_voxel_size() const
return the size of a voxel in bytes
Definition volume.h:63
const T * get_row_ptr(unsigned j, unsigned k) const
return a const pointer to the data of the j-th row in the k-th slice
Definition volume.h:114
unsigned get_component_size() const
return the size of a voxel component in bytes
Definition volume.h:61
size_t get_size() const
return size of volume in bytes
Definition volume.h:69
const T * get_slice_ptr(unsigned k) const
return a const pointer to the data of the k-th slice
Definition volume.h:108
const T * get_voxel_ptr(unsigned i, unsigned j, unsigned k) const
return a const pointer to the component data of voxel (i,j,k)
Definition volume.h:120
void set_component_format(cgv::data::ComponentFormat cf)
set a different component format
Definition volume.h:53
cgv::data::data_view & get_data_view()
return a reference to the data view
Definition volume.h:99
T get_voxel_component(unsigned i, unsigned j, unsigned k, unsigned ci=0)
return a voxel component converted to type T
Definition volume.h:126
bool empty() const
return whether volume is empty
Definition volume.h:38
cgv::type::info::TypeId get_component_type() const
return the component type
Definition volume.h:49
size_t get_slice_size() const
return the size of a slice in bytes
Definition volume.h:67
ComponentFormat
define standard formats, which should be used to avoid wrong assignment of component names
unsigned int get_type_size(TypeId tid)
function that returns the size of a type specified through TypeId
Definition type_id.cxx:18
TypeId
ids for the different types and type constructs
Definition type_id.h:12
the cgv namespace
Definition print.h:11