API Documentation
Loading...
Searching...
No Matches
MaterialRaster.h
Go to the documentation of this file.
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/ImageFactory.h>
4#include <NDEVR/VectorFunctions.h>
5#include <NDEVR/RGBColor.h>
6#include <NDEVR/INIInterface.h>
7namespace NDEVR
8{
9 /**--------------------------------------------------------------------------------------------------
10 \brief Stores information for painting pixels at a time into a 2D texture used with MaterialRaster.
11 **/
12 struct RasterInfo : public INIInterface
13 {
16 {}
17 RasterInfo(const File& ini_file)
18 : INIInterface(ini_file)
19 {}
20 bool isEnabled() const
21 {
22 return is_enabled && pixel_size > 0U;
23 }
30 bool is_enabled = false;
31 virtual void getINI(INIFactory& factory) override
32 {
33 factory.addOption("pixel_size", pixel_size);
34 factory.addOption("radial_distortion_scale", radial_distortion_scale);
35 factory.addOption("radial_distortion_offset", radial_distortion_offset);
36 factory.addOption("side_crop", side_crop);
37 factory.addOption("camera_drape_move_angle", camera_drape_move_angle);
38 factory.addOption("angle_offset", angle_offset);
39 factory.addOption("is_enabled", is_enabled);
40 }
41 };
42 /**--------------------------------------------------------------------------------------------------
43 \brief Base class for painting pixels at a time into a 2D texture.
44 **/
46 {
47 public:
48 MaterialRasterBase(const RasterInfo& raster_info)
49 : m_raster_info(raster_info)
50 {}
51 virtual void updateImage() = 0;
52 virtual void addImageBuffer(const Buffer<uint01>& pixels, const Vector<2, uint04>& size, const Matrix<fltp08>& camera_matrix) = 0;
53 virtual const String& imageID() const = 0;
54 virtual void addPixelInfo(const RGBColor& pixel, const Vector<2, fltp08>& location, uint04 weight) = 0;
55 virtual void addPixelInfo(const RGBColor& pixel, const Vector<2, uint04>& location, uint08 weight) = 0;
56 virtual void addPixelInfo(const Vector<4, fltp04>& pixel, const Vector<2, fltp08>& location, uint08 weight) = 0;
57 virtual void addPixelInfo(const Vector<4, fltp04>& pixel, const Vector<2, uint04>& location, uint08 weight) = 0;
58 protected:
60 };
61 /**--------------------------------------------------------------------------------------------------
62 \brief Stores information for painting pixels at a time into a 2D texture.
63 **/
65 {
66 public:
67 MaterialRaster(const String& image_id, const RasterInfo& raster_info)
68 : MaterialRasterBase(raster_info)
69 , m_image_id(image_id)
70 , m_color_channels(raster_info.pixel_size[X] * raster_info.pixel_size[Y], Vector<3, uint08>(0))
71 , m_color_channel_average_count(raster_info.pixel_size[X] * raster_info.pixel_size[Y], 0)
72 , m_pixels(4 * raster_info.pixel_size[X] * raster_info.pixel_size[Y], 255)
74 {
76 }
77 const String& imageID() const override
78 {
79 return m_image_id;
80 }
81 virtual void clearRaster()
82 {
83 m_color_channels.setAllToValue(Vector<3, uint08>(0));
85 }
86 virtual void setUnsetColor(RGBColor color)
87 {
88 for (uint04 y = m_update_bounds[MIN][Y]; y < m_update_bounds[MAX][Y]; y++)
89 {
90 for (uint04 x = m_update_bounds[MIN][X]; x < m_update_bounds[MAX][X]; x++)
91 {
92 uint04 pixel_index = convertToIndex({ x,y });
93 if (m_color_channel_average_count[pixel_index] == 0)
94 {
95 m_pixels[4 * pixel_index + RGBColor::r_pos] = color[RGBColor::r_pos];
96 m_pixels[4 * pixel_index + RGBColor::g_pos] = color[RGBColor::g_pos];
97 m_pixels[4 * pixel_index + RGBColor::b_pos] = color[RGBColor::b_pos];
98 }
99 }
100 }
101 }
102 virtual void updateImage() override
103 {
104 for (uint04 y = m_update_bounds[MIN][Y]; y <= m_update_bounds[MAX][Y]; y++)
105 {
106 for (uint04 x = m_update_bounds[MIN][X]; x <= m_update_bounds[MAX][X]; x++)
107 {
108 uint04 pixel_index = convertToIndex({ x,y });
109 if (m_color_channel_average_count[pixel_index] > 0)
110 {
114 }
115 }
116 }
118 }
119 static uint04 Weight(const Vertex<2, fltp08>& location, fltp08 y_dist)
120 {
121 uint04 weight = getMax(1U, cast<uint04>(1.0 / getMax(0.001, y_dist * location.magnitudeSquared())));
122 return weight;
123 }
124 virtual void addImageBuffer(const Buffer<uint01>& pixels, const Vector<2, uint04>& size, const Matrix<fltp08>& camera_matrix) override;
125 /*void addImageBuffer(const Buffer<uint01>& pixels, Camera* camera, const Model& model)
126 {
127 Vector<2, uint04> size = camera->getWindowSize().span();
128 Vector<2, fltp08> flt_size = size.as<2, fltp08>();
129 Vector<2, fltp08> half_flt_size = size.as<2, fltp08>() / 2.0;
130 Vertex<3, fltp08> last_nearest = Constant<Vertex<3, fltp08>>::Invalid;
131 if (size[X] < m_side_crop)
132 return;
133 if (size[Y] < m_side_crop)
134 return;
135 SelectionInfo info = camera->createSelectionInfo();
136 //info.allow_inverse_trans = true;
137 info.model_filter = [this](const Model& model)->bool
138 {
139 bool ignore = false;
140 ignore |= !model.getProperty<bool>(Model::e_allow_interactions);
141 //ignore |= model.getProperty<bool>(Model::e_is_application_owned);
142 ignore |= !model.getProperty<bool>(Model::e_3D_visible);
143 return !ignore;
144 };
145 //info.allow_inverse_trans = true;
146 Matrix<fltp08> inv_mat = info.current_selection.projectionTransform().invert();;
147 for (uint04 y = m_side_crop; y < size[Y] - m_side_crop; y++)
148 {
149 for (uint04 x = m_side_crop; x < size[X] - m_side_crop; x++)
150 {
151 info.clearLastSelection();
152 uint04 source_pixel_location = y * size[X] + x;
153
154 Vertex<2, fltp04> loc(x, y);
155
156 const Vector<2, fltp08> corrected_space = camera->toScreenSpace(loc);
157 const Matrix<fltp08> mat = inv_mat.invert();
158 const LineSegment<3, fltp08> selection(Vector<3, fltp08>(corrected_space, 0.0), Vector<3, fltp08>(corrected_space, 1.0));
159 info.current_selection.setSelection(mat * selection);
160
161
162 info.nearest_line.screen_distance = 0.0;
163
164 info.parseAll({ model });
165 if (!IsInvalid(info.nearest_solid.nearest_index))
166 {
167
168 //record.position = info.nearest_solid.screen_location;
169 last_nearest = info.nearestScreenLocation();
170
171 }
172 }
173 }
174 }*/
176 {
177 Vector<2, fltp08> loc = location;
178 if (loc[Y] < 0.0)//wrap around x axis
179 {
180 loc[Y] = -loc[Y];
181 loc[X] += 0.5;
182 }
183 if (loc[Y] > 1.0)//wrap around x axis
184 {
185 loc[Y] = 2.0 - loc[Y];
186 loc[X] += 0.5;
187 }
188 loc[X] = fmod(loc[X], 1.0);
189 if (loc[X] < 0.0)
190 loc[X] += 1;
191 return (loc * (m_raster_info.pixel_size - 1U).as<2, fltp08>()).as<2, uint04>();
192 }
194 {
195 return location[Y] * m_raster_info.pixel_size[X] + location[X];
196 }
197 void addPixelInfo(const RGBColor& pixel, const Vector<2, fltp08>& location, uint04 weight) override
198 {
199 if (weight > 0)
200 {
201 addPixelInfo(pixel, convertLocation(location), weight);
202 }
203 }
204 void addPixelInfo(const RGBColor& pixel, const Vector<2, uint04>& location, uint08 weight) override
205 {
206 if (weight > 0)
207 {
209 uint04 pixel_index = convertToIndex(location);
210
211 m_color_channels[pixel_index] += (weight * pixel.as<3, uint08>());
212 m_color_channel_average_count[pixel_index] += weight;
213 }
214 }
215 void addPixelInfo(const Vector<4, fltp04>& pixel, const Vector<2, fltp08>& location, uint08 weight) override
216 {
217 if(weight > 0)
218 addPixelInfo(pixel, convertLocation(location), weight);
219 }
220 void addPixelInfo(const Vector<4, fltp04>& pixel, const Vector<2, uint04>& location, uint08 weight) override
221 {
223 uint04 pixel_index = convertToIndex(location);
224 if (weight != Constant<uint08>::Max)
225 {
226 m_color_channels[pixel_index] += (weight * (pixel * 255.0f).as<3, uint08>());
227 m_color_channel_average_count[pixel_index] += weight;
228 }
229 else
230 {
231 m_color_channels[pixel_index] = (pixel * 255.0f).as<3, uint08>();
232 m_color_channel_average_count[pixel_index] = 1;
233 }
234 }
235 protected:
241 };
242 /**--------------------------------------------------------------------------------------------------
243 \brief Creates rasters for converting points and directions into 2D images.
244 **/
246 {
247 public:
248 static MaterialRasterBase* CreateRaster(const String& image_id, const RasterInfo& info);
250 protected:
251 virtual MaterialRasterBase* createRaster(const String& image_id, const RasterInfo& info) = 0;
253 };
254}
#define NDEVR_DESIGN_API
Definition DLLInfo.h:55
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:540
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:52
constexpr void addToBounds(const t_vertex &vector)
Definition Bounds.hpp:390
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
void setAllToValue(const t_o_type &fill_element, const t_index_type offset=0, t_index_type fill_size=Constant< t_index_type >::Invalid)
Definition Buffer.hpp:782
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
Contains methods for easily reading and writing to an INI file including efficient casting,...
Definition INIReader.h:68
void addOption(const String &label, Resource< Vector< t_dims, t_type > > &mem_loc)
Definition INIReader.h:76
Contains methods for easily reading and writing to an INI file including.
Definition INIInterface.h:45
static ImageFactory & DefaultFactory()
void addImageUncompressed(const String &image_id, const Buffer< uint01 > &uncompressed, bool clear_other)
Base class for painting pixels at a time into a 2D texture.
Definition MaterialRaster.h:46
virtual void updateImage()=0
virtual const String & imageID() const =0
virtual void addPixelInfo(const RGBColor &pixel, const Vector< 2, uint04 > &location, uint08 weight)=0
virtual void addImageBuffer(const Buffer< uint01 > &pixels, const Vector< 2, uint04 > &size, const Matrix< fltp08 > &camera_matrix)=0
MaterialRasterBase(const RasterInfo &raster_info)
Definition MaterialRaster.h:48
RasterInfo m_raster_info
Definition MaterialRaster.h:59
virtual void addPixelInfo(const Vector< 4, fltp04 > &pixel, const Vector< 2, uint04 > &location, uint08 weight)=0
virtual void addPixelInfo(const RGBColor &pixel, const Vector< 2, fltp08 > &location, uint04 weight)=0
virtual void addPixelInfo(const Vector< 4, fltp04 > &pixel, const Vector< 2, fltp08 > &location, uint08 weight)=0
Creates rasters for converting points and directions into 2D images.
Definition MaterialRaster.h:246
static void SetDefaultMaterialRasterFactory(MaterialRasterFactory *factory)
static MaterialRasterFactory * s_default_raster_factory
Definition MaterialRaster.h:252
static MaterialRasterBase * CreateRaster(const String &image_id, const RasterInfo &info)
virtual MaterialRasterBase * createRaster(const String &image_id, const RasterInfo &info)=0
Stores information for painting pixels at a time into a 2D texture.
Definition MaterialRaster.h:65
void addPixelInfo(const Vector< 4, fltp04 > &pixel, const Vector< 2, fltp08 > &location, uint08 weight) override
Definition MaterialRaster.h:215
Bounds< 2, uint04 > m_update_bounds
Definition MaterialRaster.h:240
void addPixelInfo(const RGBColor &pixel, const Vector< 2, fltp08 > &location, uint04 weight) override
Definition MaterialRaster.h:197
Buffer< Vector< 3, uint08 > > m_color_channels
Definition MaterialRaster.h:237
MaterialRaster(const String &image_id, const RasterInfo &raster_info)
Definition MaterialRaster.h:67
void addPixelInfo(const RGBColor &pixel, const Vector< 2, uint04 > &location, uint08 weight) override
Definition MaterialRaster.h:204
static uint04 Weight(const Vertex< 2, fltp08 > &location, fltp08 y_dist)
Definition MaterialRaster.h:119
uint04 convertToIndex(const Vector< 2, uint04 > &location) const
Definition MaterialRaster.h:193
Vector< 2, uint04 > convertLocation(const Vector< 2, fltp08 > &location) const
Definition MaterialRaster.h:175
virtual void addImageBuffer(const Buffer< uint01 > &pixels, const Vector< 2, uint04 > &size, const Matrix< fltp08 > &camera_matrix) override
virtual void clearRaster()
Definition MaterialRaster.h:81
const String & imageID() const override
Definition MaterialRaster.h:77
virtual void updateImage() override
Definition MaterialRaster.h:102
Buffer< uint01 > m_pixels
Definition MaterialRaster.h:239
void addPixelInfo(const Vector< 4, fltp04 > &pixel, const Vector< 2, uint04 > &location, uint08 weight) override
Definition MaterialRaster.h:220
Buffer< uint08 > m_color_channel_average_count
Definition MaterialRaster.h:238
virtual void setUnsetColor(RGBColor color)
Definition MaterialRaster.h:86
String m_image_id
Definition MaterialRaster.h:236
Definition Matrix.hpp:176
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:54
static const uint01 r_pos
Definition RGBColor.h:56
static const uint01 g_pos
Definition RGBColor.h:57
static const uint01 b_pos
Definition RGBColor.h:58
The core String class for the NDEVR API.
Definition String.h:69
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
constexpr t_type magnitudeSquared() const
Definition Vector.hpp:426
constexpr Vector< t_dims, t_new_type > as() const
Definition Vector.hpp:300
A vertex or point. A specific type of Vector used primarily for spacial location information.
Definition Vertex.hpp:48
Definition ACIColor.h:37
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator The only requirement is that t_type have > ...
Definition BaseFunctions.hpp:94
@ MIN
Definition BaseValues.hpp:196
@ MAX
Definition BaseValues.hpp:197
@ DEGREES
Definition Angle.h:58
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
Definition BaseValues.hpp:106
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
@ Y
Definition BaseValues.hpp:169
@ X
Definition BaseValues.hpp:167
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
Stores information for painting pixels at a time into a 2D texture used with MaterialRaster.
Definition MaterialRaster.h:13
bool is_enabled
Definition MaterialRaster.h:30
virtual void getINI(INIFactory &factory) override
Definition MaterialRaster.h:31
fltp08 radial_distortion_scale
Definition MaterialRaster.h:25
uint04 side_crop
Definition MaterialRaster.h:29
Vector< 2, uint04 > pixel_size
Definition MaterialRaster.h:24
RasterInfo(const File &ini_file)
Definition MaterialRaster.h:17
bool isEnabled() const
Definition MaterialRaster.h:20
Vector< 2, Angle< fltp08 > > angle_offset
Definition MaterialRaster.h:28
RasterInfo()
Definition MaterialRaster.h:14
Vector< 2, Angle< fltp08 > > camera_drape_move_angle
Definition MaterialRaster.h:27
fltp08 radial_distortion_offset
Definition MaterialRaster.h:26