MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / pickObjects

Method pickObjects

source/MRViewer/MRViewportGL.cpp:179–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177}
178
179ViewportGL::PickResults ViewportGL::pickObjects( const PickParameters& params, const std::vector<Vector2i>& picks ) const
180{
181 if ( !inited_ )
182 return {};
183 MR_TIMER;
184
185 int width = params.baseRenderParams.viewport.z;
186 int height = params.baseRenderParams.viewport.w;
187 PickResults results( picks.size() );
188
189 Box2i box;
190 for ( const auto& pick : picks )
191 {
192 if ( pick.x < 0 || pick.x >= width ||
193 pick.y < 0 || pick.y >= height )
194 continue;
195 box.include( pick );
196 }
197
198 Vector2i size;
199 if ( box.valid() )
200 size = box.size() + Vector2i::diagonal( 1 );
201
202 auto resColors = pickObjectsInRect_( params, box );
203
204 // read face and geom
205 for ( int i = 0; i < results.size(); ++i )
206 {
207 auto pick = picks[i];
208 if ( pick.x < 0 || pick.x >= width ||
209 pick.y < 0 || pick.y >= height )
210 continue;
211 pick -= box.min;
212 auto ind = pick.x + ( size.y - pick.y - 1 ) * size.x;
213 const auto& color = resColors[ind].color;
214
215 unsigned primId = color[0];
216 unsigned geomId = color[1];
217 float z = float(color[3])/float( 0xffffffff );
218
219 results[i] = { {geomId ,primId },z };
220 }
221
222 // Filter results
223 for ( int i = 0; i < results.size(); ++i )
224 {
225 if ( results[i].geomId >= params.renderVector.size() || !params.renderVector[results[i].geomId] )
226 results[i] = {};
227 }
228
229 return results;
230}
231
232std::vector<unsigned> ViewportGL::findUniqueObjectsInRect( const PickParameters& params, const Box2i& rect,
233 int maxRenderResolutionSide ) const

Callers 1

multiPickObjectsMethod · 0.80

Calls 4

diagonalFunction · 0.85
sizeMethod · 0.45
includeMethod · 0.45
validMethod · 0.45

Tested by

no test coverage detected