cgv
Loading...
Searching...
No Matches
colored_model.cxx
1#include "colored_model.h"
2#include <cassert>
3
4namespace cgv {
5 namespace media {
6
19 {
20 color_storage_ptr = cm.color_storage_ptr;
21 cm.color_storage_ptr = nullptr;
22 }
31 {
32 color_storage_ptr = cm.color_storage_ptr;
33 cm.color_storage_ptr = nullptr;
34 return *this;
35 }
44
46 {
47 return color_storage_ptr != 0;
48 }
49
50 void colored_model::set_color(size_t i, const void* col_ptr)
51 {
52 assert(has_colors());
53 color_storage_ptr->set_color(i, col_ptr);
54 }
55 void colored_model::set_color(size_t i, const rgb& col)
56 {
57 assert(has_colors());
59 }
60 void colored_model::set_color(size_t i, const rgba& col)
61 {
62 assert(has_colors());
64 }
65 void colored_model::set_color(size_t i, const rgb8& col)
66 {
67 assert(has_colors());
69 }
70 void colored_model::set_color(size_t i, const rgba8& col)
71 {
72 assert(has_colors());
74 }
75
76 void colored_model::put_color(size_t i, rgb& col) const
77 {
78 assert(has_colors());
80 }
81 void colored_model::put_color(size_t i, void* col_ptr) const
82 {
83 assert(has_colors());
84 color_storage_ptr->put_color(i, col_ptr);
85 }
86 void colored_model::put_color(size_t i, rgba& col) const
87 {
88 assert(has_colors());
90 }
91 void colored_model::put_color(size_t i, rgb8& col) const
92 {
93 assert(has_colors());
95 }
96 void colored_model::put_color(size_t i, rgba8& col) const
97 {
98 assert(has_colors());
100 }
101
103 {
105 }
107 void colored_model::resize_colors(size_t nr_colors)
108 {
110 color_storage_ptr->resize(nr_colors);
111 else
112 ensure_colors(CT_RGBA8, nr_colors);
113 }
119 const void* colored_model::get_color_data_ptr() const
120 {
122 }
123 const void* colored_model::get_color_data_vector_ptr() const
124 {
126 }
127 void* colored_model::ref_color_data_ptr()
128 {
130 }
131 void* colored_model::ref_color_data_vector_ptr()
132 {
134 }
136 {
138 }
139
140 void colored_model::ensure_colors(ColorType _color_type, size_t nr_colors)
141 {
142 if (color_storage_ptr) {
143 if (color_storage_ptr->get_color_type() == _color_type)
144 return;
145 abst_color_storage* new_storage_ptr;
146 switch (_color_type) {
147 case CT_RGB: new_storage_ptr = new color_storage<rgb>(*color_storage_ptr); break;
148 case CT_RGBA: new_storage_ptr = new color_storage<rgba>(*color_storage_ptr); break;
149 case CT_RGB8: new_storage_ptr = new color_storage<rgb8>(*color_storage_ptr); break;
150 case CT_RGBA8: new_storage_ptr = new color_storage<rgba8>(*color_storage_ptr); break;
151 }
152 delete color_storage_ptr;
153 color_storage_ptr = new_storage_ptr;
154 }
155 else {
156 switch (_color_type) {
157 case CT_RGB: color_storage_ptr = new color_storage<rgb>(); break;
158 case CT_RGBA: color_storage_ptr = new color_storage<rgba>(); break;
159 case CT_RGB8: color_storage_ptr = new color_storage<rgb8>(); break;
160 case CT_RGBA8: color_storage_ptr = new color_storage<rgba8>(); break;
161 }
162 if (nr_colors != -1)
163 color_storage_ptr->resize(nr_colors);
164 }
165 }
168 {
169 if (color_storage_ptr) {
170 delete color_storage_ptr;
172 }
173 }
174
175 }
176}
interface for color storage of different internal types
virtual void set_color(size_t i, const void *col_ptr)=0
set i-th color to color of type stored in storage
virtual const void * get_data_ptr() const =0
return a const void pointer to the color data
virtual size_t get_nr_colors() const =0
return number colors stored in color storage
virtual abst_color_storage * clone() const =0
clone the color storage
virtual void * ref_data_vector_ptr()=0
return a void pointer to the color data vector
virtual const void * get_data_vector_ptr() const =0
return a const void pointer to the color data vector
virtual void * ref_data_ptr()=0
return a void pointer to the color data
virtual void resize(size_t nr_colors)=0
resize to the given number of colors
ColorType get_color_type() const
return color type of color storage
virtual void put_color(size_t i, void *col_ptr) const =0
set color of type stored in storage to i-th color
size_t get_color_size() const
return size of a single color in byte
template implementation of color storage model
coordinate type independent base class of simple mesh data structure that handles indices and colors.
colored_model & operator=(const colored_model &cm)
assignment operator
void destruct_colors()
destruct color storage
colored_model()
construct colored model
void set_color(size_t i, const void *col_ptr)
set i-th color to color of type stored in storage
ColorType get_color_storage_type() const
return storage type of colors, if no colors are allocated CT_RGBA8 is returned
size_t get_color_size() const
return the size of one allocated color in byte
virtual ~colored_model()
destruct colored model
bool has_colors() const
check whether colors have been allocated
void ensure_colors(ColorType _color_type, size_t nr_colors=-1)
ensure that colors are allocated and of given storage type
abst_color_storage * color_storage_ptr
pointer to color storage
void put_color(size_t i, void *col_ptr) const
set color of type stored in storage to i-th color
size_t get_nr_colors() const
return number of allocated colors
void resize_colors(size_t nr_colors)
resize the color storage to given number of colors
the cgv namespace
Definition print.h:11