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 struct RasterInfo : public INIInterface
10 {
13 {}
14 RasterInfo(const File& ini_file)
15 : INIInterface(ini_file)
16 {}
17 bool isEnabled() const
18 {
19 return is_enabled && pixel_size > 0U;
20 }
27 bool is_enabled = false;
28 virtual void getINI(INIFactory& factory) override
29 {
30 factory.addOption("pixel_size", pixel_size);
31 factory.addOption("radial_distortion_scale", radial_distortion_scale);
32 factory.addOption("radial_distortion_offset", radial_distortion_offset);
33 factory.addOption("side_crop", side_crop);
34 factory.addOption("camera_drape_move_angle", camera_drape_move_angle);
35 factory.addOption("angle_offset", angle_offset);
36 factory.addOption("is_enabled", is_enabled);
37 }
38 };
40 {
41 public:
42 MaterialRasterBase(const RasterInfo& raster_info)
43 : m_raster_info(raster_info)
44 {}
45 virtual void updateImage() = 0;
46 virtual void addImageBuffer(const Buffer<uint01>& pixels, const Vector<2, uint04>& size, const Matrix<fltp08>& camera_matrix) = 0;
47 virtual const String& imageID() const = 0;
48 virtual void addPixelInfo(const RGBColor& pixel, const Vector<2, fltp08>& location, uint04 weight) = 0;
49 virtual void addPixelInfo(const RGBColor& pixel, const Vector<2, uint04>& location, uint08 weight) = 0;
50 virtual void addPixelInfo(const Vector<4, fltp04>& pixel, const Vector<2, fltp08>& location, uint08 weight) = 0;
51 virtual void addPixelInfo(const Vector<4, fltp04>& pixel, const Vector<2, uint04>& location, uint08 weight) = 0;
52 protected:
54 };
56 {
57 public:
58 MaterialRaster(const String& image_id, const RasterInfo& raster_info)
59 : MaterialRasterBase(raster_info)
60 , m_image_id(image_id)
61 , m_color_channels(raster_info.pixel_size[X] * raster_info.pixel_size[Y], Vector<3, uint08>(0))
62 , m_color_channel_average_count(raster_info.pixel_size[X] * raster_info.pixel_size[Y], 0)
63 , m_pixels(4 * raster_info.pixel_size[X] * raster_info.pixel_size[Y], 255)
65 {
67 }
68 const String& imageID() const override
69 {
70 return m_image_id;
71 }
72 virtual void clearRaster()
73 {
74 m_color_channels.setAllToValue(Vector<3, uint08>(0));
76 }
77 virtual void setUnsetColor(RGBColor color)
78 {
79 for (uint04 y = m_update_bounds[MIN][Y]; y < m_update_bounds[MAX][Y]; y++)
80 {
81 for (uint04 x = m_update_bounds[MIN][X]; x < m_update_bounds[MAX][X]; x++)
82 {
83 uint04 pixel_index = convertToIndex({ x,y });
84 if (m_color_channel_average_count[pixel_index] == 0)
85 {
86 m_pixels[4 * pixel_index + RGBColor::r_pos] = color[RGBColor::r_pos];
87 m_pixels[4 * pixel_index + RGBColor::g_pos] = color[RGBColor::g_pos];
88 m_pixels[4 * pixel_index + RGBColor::b_pos] = color[RGBColor::b_pos];
89 }
90 }
91 }
92 }
93 virtual void updateImage() override
94 {
95 for (uint04 y = m_update_bounds[MIN][Y]; y <= m_update_bounds[MAX][Y]; y++)
96 {
97 for (uint04 x = m_update_bounds[MIN][X]; x <= m_update_bounds[MAX][X]; x++)
98 {
99 uint04 pixel_index = convertToIndex({ x,y });
100 if (m_color_channel_average_count[pixel_index] > 0)
101 {
105 }
106 }
107 }
109 }
110 static uint04 Weight(const Vertex<2, fltp08>& location, fltp08 y_dist)
111 {
112 uint04 weight = getMax(1U, cast<uint04>(1.0 / getMax(0.001, y_dist * location.magnitudeSquared())));
113 return weight;
114 }
115 virtual void addImageBuffer(const Buffer<uint01>& pixels, const Vector<2, uint04>& size, const Matrix<fltp08>& camera_matrix) override;
116 /*void addImageBuffer(const Buffer<uint01>& pixels, Camera* camera, const Model& model)
117 {
118 Vector<2, uint04> size = camera->getWindowSize().span();
119 Vector<2, fltp08> flt_size = size.as<2, fltp08>();
120 Vector<2, fltp08> half_flt_size = size.as<2, fltp08>() / 2.0;
121 Vertex<3, fltp08> last_nearest = Constant<Vertex<3, fltp08>>::NaN;
122 if (size[X] < m_side_crop)
123 return;
124 if (size[Y] < m_side_crop)
125 return;
126 SelectionInfo info = camera->createSelectionInfo();
127 //info.allow_inverse_trans = true;
128 info.model_filter = [this](const Model& model)->bool
129 {
130 bool ignore = false;
131 ignore |= !model.getProperty<bool>(Model::e_allow_interactions);
132 //ignore |= model.getProperty<bool>(Model::e_is_application_owned);
133 ignore |= !model.getProperty<bool>(Model::e_3D_visible);
134 return !ignore;
135 };
136 //info.allow_inverse_trans = true;
137 Matrix<fltp08> inv_mat = info.current_selection.projectionTransform().invert();;
138 for (uint04 y = m_side_crop; y < size[Y] - m_side_crop; y++)
139 {
140 for (uint04 x = m_side_crop; x < size[X] - m_side_crop; x++)
141 {
142 info.clearLastSelection();
143 uint04 source_pixel_location = y * size[X] + x;
144
145 Vertex<2, fltp04> loc(x, y);
146
147 const Vector<2, fltp08> corrected_space = camera->toScreenSpace(loc);
148 const Matrix<fltp08> mat = inv_mat.invert();
149 const LineSegment<3, fltp08> selection(Vector<3, fltp08>(corrected_space, 0.0), Vector<3, fltp08>(corrected_space, 1.0));
150 info.current_selection.setSelection(mat * selection);
151
152
153 info.nearest_line.screen_distance = 0.0;
154
155 info.parseAll({ model });
156 if (!isNaN(info.nearest_solid.nearest_index))
157 {
158
159 //record.position = info.nearest_solid.screen_location;
160 last_nearest = info.nearestScreenLocation();
161
162 }
163 }
164 }
165 }*/
167 {
168 Vector<2, fltp08> loc = location;
169 if (loc[Y] < 0.0)//wrap around x axis
170 {
171 loc[Y] = -loc[Y];
172 loc[X] += 0.5;
173 }
174 if (loc[Y] > 1.0)//wrap around x axis
175 {
176 loc[Y] = 2.0 - loc[Y];
177 loc[X] += 0.5;
178 }
179 loc[X] = fmod(loc[X], 1.0);
180 if (loc[X] < 0.0)
181 loc[X] += 1;
182 return (loc * (m_raster_info.pixel_size - 1U).as<2, fltp08>()).as<2, uint04>();
183 }
185 {
186 return location[Y] * m_raster_info.pixel_size[X] + location[X];
187 }
188 void addPixelInfo(const RGBColor& pixel, const Vector<2, fltp08>& location, uint04 weight) override
189 {
190 if (weight > 0)
191 {
192 addPixelInfo(pixel, convertLocation(location), weight);
193 }
194 }
195 void addPixelInfo(const RGBColor& pixel, const Vector<2, uint04>& location, uint08 weight) override
196 {
197 if (weight > 0)
198 {
200 uint04 pixel_index = convertToIndex(location);
201
202 m_color_channels[pixel_index] += (weight * pixel.as<3, uint08>());
203 m_color_channel_average_count[pixel_index] += weight;
204 }
205 }
206 void addPixelInfo(const Vector<4, fltp04>& pixel, const Vector<2, fltp08>& location, uint08 weight) override
207 {
208 if(weight > 0)
209 addPixelInfo(pixel, convertLocation(location), weight);
210 }
211 void addPixelInfo(const Vector<4, fltp04>& pixel, const Vector<2, uint04>& location, uint08 weight) override
212 {
214 uint04 pixel_index = convertToIndex(location);
215 if (weight != Constant<uint08>::Max)
216 {
217 m_color_channels[pixel_index] += (weight * (pixel * 255.0f).as<3, uint08>());
218 m_color_channel_average_count[pixel_index] += weight;
219 }
220 else
221 {
222 m_color_channels[pixel_index] = (pixel * 255.0f).as<3, uint08>();
223 m_color_channel_average_count[pixel_index] = 1;
224 }
225 }
226 protected:
232 };
233
235 {
236 public:
237 static MaterialRasterBase* CreateRaster(const String& image_id, const RasterInfo& info);
238 static void SetDefaultMaterialRasterFactory(MaterialRasterFactory* factory);
239 protected:
240 virtual MaterialRasterBase* createRaster(const String& image_id, const RasterInfo& info) = 0;
242 };
243}
#define NDEVR_DESIGN_API
Definition DLLInfo.h:77
Stores an angle in an optimized format.
Definition StringStream.h:352
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:57
constexpr void addToBounds(const t_vertex &vector)
Adds to the bounds such that the new bounds fully encompasses the argument.
Definition Bounds.hpp:498
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
void setAllToValue(const t_o_type &fill_element, const t_index_type offset=0, t_index_type fill_size=Constant< t_index_type >::NaN)
Definition Buffer.hpp:1378
Definition File.h:47
Definition INIReader.h:57
void addOption(const String &label, Resource< Vector< t_dims, t_type > > &mem_loc)
Definition INIReader.h:236
Definition INIInterface.h:40
static ImageFactory & DefaultFactory()
void addImageUncompressed(const String &image_id, const Buffer< uint01 > &uncompressed, bool clear_other)
Definition MaterialRaster.h:40
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:42
RasterInfo m_raster_info
Definition MaterialRaster.h:53
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
Definition MaterialRaster.h:235
static MaterialRasterFactory * s_default_raster_factory
Definition MaterialRaster.h:241
virtual MaterialRasterBase * createRaster(const String &image_id, const RasterInfo &info)=0
Definition MaterialRaster.h:56
void addPixelInfo(const Vector< 4, fltp04 > &pixel, const Vector< 2, fltp08 > &location, uint08 weight) override
Definition MaterialRaster.h:206
Bounds< 2, uint04 > m_update_bounds
Definition MaterialRaster.h:231
virtual void addImageBuffer(const Buffer< uint01 > &pixels, const Vector< 2, uint04 > &size, const Matrix< fltp08 > &camera_matrix) override
Definition MaterialRaster.cpp:16
void addPixelInfo(const RGBColor &pixel, const Vector< 2, fltp08 > &location, uint04 weight) override
Definition MaterialRaster.h:188
Buffer< Vector< 3, uint08 > > m_color_channels
Definition MaterialRaster.h:228
MaterialRaster(const String &image_id, const RasterInfo &raster_info)
Definition MaterialRaster.h:58
void addPixelInfo(const RGBColor &pixel, const Vector< 2, uint04 > &location, uint08 weight) override
Definition MaterialRaster.h:195
static uint04 Weight(const Vertex< 2, fltp08 > &location, fltp08 y_dist)
Definition MaterialRaster.h:110
uint04 convertToIndex(const Vector< 2, uint04 > &location) const
Definition MaterialRaster.h:184
Vector< 2, uint04 > convertLocation(const Vector< 2, fltp08 > &location) const
Definition MaterialRaster.h:166
virtual void clearRaster()
Definition MaterialRaster.h:72
const String & imageID() const override
Definition MaterialRaster.h:68
virtual void updateImage() override
Definition MaterialRaster.h:93
Buffer< uint01 > m_pixels
Definition MaterialRaster.h:230
void addPixelInfo(const Vector< 4, fltp04 > &pixel, const Vector< 2, uint04 > &location, uint08 weight) override
Definition MaterialRaster.h:211
Buffer< uint08 > m_color_channel_average_count
Definition MaterialRaster.h:229
virtual void setUnsetColor(RGBColor color)
Definition MaterialRaster.h:77
String m_image_id
Definition MaterialRaster.h:227
Definition Matrix.hpp:173
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:53
static const uint01 r_pos
Definition RGBColor.h:55
static const uint01 g_pos
Definition RGBColor.h:56
static const uint01 b_pos
Definition RGBColor.h:57
Definition String.h:40
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
constexpr t_type magnitudeSquared() const
Definition Vector.hpp:458
constexpr Vector< t_dims, t_new_type > as() const
Definition Vector.hpp:324
A vertex.
Definition Vertex.hpp:54
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.
Definition BaseFunctions.hpp:116
@ MIN
Definition BaseValues.hpp:226
@ MAX
Definition BaseValues.hpp:227
@ DEGREES
Definition Angle.h:66
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer -Can represent exact integer values 0 thro...
Definition BaseValues.hpp:132
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition BaseValues.hpp:272
Definition MaterialRaster.h:10
bool is_enabled
Definition MaterialRaster.h:27
virtual void getINI(INIFactory &factory) override
Definition MaterialRaster.h:28
fltp08 radial_distortion_scale
Definition MaterialRaster.h:22
uint04 side_crop
Definition MaterialRaster.h:26
Vector< 2, uint04 > pixel_size
Definition MaterialRaster.h:21
RasterInfo(const File &ini_file)
Definition MaterialRaster.h:14
bool isEnabled() const
Definition MaterialRaster.h:17
Vector< 2, Angle< fltp08 > > angle_offset
Definition MaterialRaster.h:25
RasterInfo()
Definition MaterialRaster.h:11
Vector< 2, Angle< fltp08 > > camera_drape_move_angle
Definition MaterialRaster.h:24
fltp08 radial_distortion_offset
Definition MaterialRaster.h:23