My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008-2010, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of Image Engine Design nor the names of any
// other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <algorithm>
#include <cassert>

#include "boost/format.hpp"

#include "IECore/Reader.h"
#include "IECore/ImagePrimitive.h"

#include "IECore/Random.h"
#include "IECore/PrimitiveVariable.h"
#include "IECore/PointsPrimitive.h"
#include "IECore/ObjectParameter.h"
#include "IECore/NumericParameter.h"
#include "IECore/CompoundParameter.h"
#include "IECore/CompoundObject.h"
#include "IECore/Object.h"
#include "IECore/BoundedKDTree.h"
#include "IECore/MeshPrimitive.h"
#include "IECore/TriangulateOp.h"
#include "IECore/TriangleAlgo.h"
#include "IECore/SimpleTypedData.h"
#include "IECore/VectorTypedData.h"
#include "IECore/MeshPrimitiveEvaluator.h"
#include "IECore/ImagePrimitiveEvaluator.h"
#include "IECore/KDTree.h"
#include "IECore/MessageHandler.h"
#include "IECore/SweepAndPrune.h"

#include "IECore/PointRepulsionOp.h"

using namespace IECore;
using namespace Imath;
using namespace std;

IE_CORE_DEFINERUNTIMETYPED( PointRepulsionOp );

PointRepulsionOp::PointRepulsionOp()
: ModifyOp(
"The PointRepulsionOp pushes points around a surface to give them a more even distribution.",
new PointsPrimitiveParameter(
"result",
"Resulting points after repulsion over mesh.",
new PointsPrimitive()
),
new PointsPrimitiveParameter(
"input",
"The input points to relax by near-neighbour repulsion",
new PointsPrimitive()
)
)
{

m_meshParameter = new MeshPrimitiveParameter(
"mesh",
"The mesh over which the points have been distributed",
new MeshPrimitive()
);

m_imageParameter = new ImagePrimitiveParameter(
"image",
"The image specifying the density map.",
new ImagePrimitive()
);

StringParameter::PresetsContainer channelNamePresets;
channelNamePresets.push_back( StringParameter::Preset( "R", "R" ) );
channelNamePresets.push_back( StringParameter::Preset( "G", "G" ) );
channelNamePresets.push_back( StringParameter::Preset( "B", "B" ) );
channelNamePresets.push_back( StringParameter::Preset( "A", "A" ) );
channelNamePresets.push_back( StringParameter::Preset( "Y", "Y" ) );

m_channelNameParameter = new StringParameter(
"channelName",
"The name of the floating point channel in the image to use as the density map.",
"Y",
channelNamePresets,
false
);

m_numIterationsParameter = new IntParameter(
"numIterations",
"The number of repulsion iterations to apply.",
5000,
1
);

m_magnitudeParameter = new FloatParameter(
"magnitude",
"The magnitude of the force applied by each individual repulsion.",
0.01f,
1.e-10f
);

m_weightsNameParameter = new StringParameter(
"weightsName",
"The name of the primvar in the PointsPrimitive to use as the per-point weights",
""
);

parameters()->addParameter( m_imageParameter );
parameters()->addParameter( m_channelNameParameter );
parameters()->addParameter( m_meshParameter );
parameters()->addParameter( m_numIterationsParameter );
parameters()->addParameter( m_magnitudeParameter );
parameters()->addParameter( m_weightsNameParameter );
}

PointRepulsionOp::~PointRepulsionOp()
{
}

MeshPrimitiveParameter * PointRepulsionOp::meshParameter()
{
return m_meshParameter;
}

const MeshPrimitiveParameter * PointRepulsionOp::meshParameter() const
{
return m_meshParameter;
}


ImagePrimitiveParameter * PointRepulsionOp::imageParameter()
{
return m_imageParameter;
}

const ImagePrimitiveParameter * PointRepulsionOp::imageParameter() const
{
return m_imageParameter;
}

StringParameter * PointRepulsionOp::channelNameParameter()
{
return m_channelNameParameter;
}

const StringParameter * PointRepulsionOp::channelNameParameter() const
{
return m_channelNameParameter;
}

IntParameter * PointRepulsionOp::numIterationsParameter()
{
return m_numIterationsParameter;
}

const IntParameter * PointRepulsionOp::numIterationsParameter() const
{
return m_numIterationsParameter;
}

FloatParameter * PointRepulsionOp::magnitudeParameter()
{
return m_magnitudeParameter;
}

const FloatParameter * PointRepulsionOp::magnitudeParameter() const
{
return m_magnitudeParameter;
}

StringParameter * PointRepulsionOp::weightsNameParameter()
{
return m_weightsNameParameter;
}

const StringParameter * PointRepulsionOp::weightsNameParameter() const
{
return m_weightsNameParameter;
}

void PointRepulsionOp::getNearestPointsAndDensities( ImagePrimitiveEvaluator * imageEvaluator, const PrimitiveVariable &densityPrimVar, MeshPrimitiveEvaluator * meshEvaluator, const PrimitiveVariable &sPrimVar, const PrimitiveVariable &tPrimVar, std::vector<Imath::V3f> &points, std::vector<float> &densities )
{
densities.resize( points.size() );

PrimitiveEvaluator::ResultPtr meshResult = meshEvaluator->createResult();
PrimitiveEvaluator::ResultPtr imageResult = imageEvaluator->createResult();

for ( std::vector<Imath::V3f>::size_type p = 0; p < points.size(); p++ )
{
bool found = meshEvaluator->closestPoint( points[p], meshResult );
if ( !found )
{
throw InvalidArgumentException( "PointRepulsionOp: Invaid mesh - closest point is undefined" );
}

points[p] = meshResult->point();

Imath::V2f uv(
meshResult->floatPrimVar( sPrimVar ),
meshResult->floatPrimVar( tPrimVar )
);

/// \todo Texture repeat
float repeatU = 1.0;
float repeatV = 1.0;

/// \todo Wrap modes
bool wrapU = true;
bool wrapV = true;

Imath::V2f placedUv(
uv.x * repeatU,
uv.y * repeatV
);

if ( wrapU )
{
placedUv.x = fmodf( placedUv.x, 1.0f );
}

if ( wrapV )
{
placedUv.y = fmodf( placedUv.y, 1.0f );
}

imageEvaluator->pointAtUV( placedUv, imageResult );

densities[p] = imageResult->floatPrimVar( densityPrimVar );
}
}

void PointRepulsionOp::calculateForces( std::vector<V3f> &points, std::vector<float> &radii, std::vector<Imath::Box3f> &bounds, std::vector<Imath::V3f> &forces, Imath::Rand48 &generator, std::vector<float> &densities, float densityInv )
{
unsigned numPoints = points.size();

Box3fTree tree( bounds.begin(), bounds.end(), 16 );

typedef std::vector< Box3fTree::Iterator> Bounds;

for ( std::vector<V3f>::size_type p = 0; p < numPoints; p++ )
{
Bounds approximateBounds;
tree.intersectingBounds( bounds[p], approximateBounds );

for ( Bounds::const_iterator it = approximateBounds.begin(); it != approximateBounds.end(); ++it )
{
const std::vector<V3f>::size_type other = *it - bounds.begin();
assert( other < numPoints );
assert( other < radii.size() );

if ( p != other )
{
Imath::V3f separation = points[p] - points[other];

float dist = separation.length();

float densityDiff = 1.0f - fabsf( densities[p] * densityInv - densities[other] * densityInv );

if ( dist < radii[p] + radii[other] )
{
float overlap = radii[p] + radii[other] - dist;
assert( overlap >= 0.0f );
float overlapNorm = overlap / ( radii[p] + radii[other] );

if ( dist < 1.e-6f )
{
/// Points are incident, so force acts to move current point away from neighbour in a random direction
forces[ p ] += densityDiff * overlapNorm * solidSphereRand< V3f, Rand48 >( generator ) ;
}
else
{
/// Force acts to move current point away from neighbour along their line of separation
forces[ p ] += densityDiff * overlapNorm * separation.normalized() ;
}
}
}
}
}
}


void PointRepulsionOp::modify( Object * object, const CompoundObject * operands )
{
MeshPrimitive * mesh = m_meshParameter->getTypedValue<MeshPrimitive>();
assert( mesh );

TriangulateOpPtr op = new TriangulateOp();
op->inputParameter()->setValue( mesh );
op->toleranceParameter()->setNumericValue( 1.e-3f );
mesh = runTimeCast< MeshPrimitive > ( op->operate() );
assert( mesh );

PointsPrimitive * pointsPrimitive = runTimeCast< PointsPrimitive, Object >( object );
assert( pointsPrimitive );

ImagePrimitivePtr image = runTimeCast<ImagePrimitive>( m_imageParameter->getValue()->copy() );
assert( image );

const std::string &channelName = m_channelNameParameter->getTypedValue();

const int numIterations = m_numIterationsParameter->getNumericValue();

const float magnitude = m_magnitudeParameter->getNumericValue();

const std::string &weightsName = m_weightsNameParameter->getTypedValue();

PrimitiveVariableMap::const_iterator sIt = mesh->variables.find( "s" );
if ( sIt != mesh->variables.end() )
{
if ( sIt->second.interpolation != PrimitiveVariable::FaceVarying )
{
throw InvalidArgumentException( "PointRepulsionOp: MeshPrimitive variable 's' must have facevarying interpolation" );
}
if ( !runTimeCast< FloatVectorData >( sIt->second.data ) )
{
throw InvalidArgumentException( "PointRepulsionOp: MeshPrimitive variable 's' must be of type FloatVectorData" );
}
}

PrimitiveVariableMap::const_iterator tIt = mesh->variables.find( "t" );
if ( tIt != mesh->variables.end() )
{
if ( tIt->second.interpolation != PrimitiveVariable::FaceVarying )
{
throw InvalidArgumentException( "PointRepulsionOp: MeshPrimitive variable 't' must have facevarying interpolation" );
}

if ( !runTimeCast< FloatVectorData >( tIt->second.data ) )
{
throw InvalidArgumentException( "PointRepulsionOp: MeshPrimitive variable 't' must be of type FloatVectorData" );
}
}

V3fVectorDataPtr pData = 0;
PrimitiveVariableMap::const_iterator pIt = pointsPrimitive->variables.find( "P" );
if ( pIt != pointsPrimitive->variables.end() )
{
if ( pIt->second.interpolation != PrimitiveVariable::Vertex )
{
throw InvalidArgumentException( "PointRepulsionOp: PointsPrimitive variable 'P' must have vertex interpolation" );
}

pData = runTimeCast< V3fVectorData >( pIt->second.data );
if ( !pData )
{
throw InvalidArgumentException( "PointRepulsionOp: PointsPrimitive variable 'P' must be of type V3fVectorData" );
}
}
else
{
throw InvalidArgumentException( "PointRepulsionOp: PointsPrimitive variable 'P' must be present" );
}

typedef V3fVectorData::ValueType PointArray;
PointArray &points = pData->writable();
PointArray::size_type numPoints = points.size();

FloatVectorDataPtr weights = 0;
if ( weightsName.size() )
{
PrimitiveVariableMap::const_iterator wIt = pointsPrimitive->variables.find( weightsName );
if ( wIt != pointsPrimitive->variables.end() )
{
if ( wIt->second.interpolation != PrimitiveVariable::Vertex )
{
throw InvalidArgumentException(( boost::format( "PointRepulsionOp: PointsPrimitive variable '%s' must have vertex interpolation" ) % weightsName ).str() );
}

weights = runTimeCast< FloatVectorData >( wIt->second.data );
if ( !weights )
{
throw InvalidArgumentException(( boost::format( "PointRepulsionOp: PointsPrimitive variable '%s' must be of type FloatVectorData" ) % weightsName ).str() );
}

assert( weights );
if ( weights->readable().size() != numPoints )
{
throw InvalidArgumentException(( boost::format( "PointRepulsionOp: PointsPrimitive variable '%s' of incorrect size" ) % weightsName ).str() );
}
}
else
{
throw InvalidArgumentException(( boost::format( "PointRepulsionOp: PointsPrimitive weights variable '%s' must be present" ) % weightsName ).str() );
}
}

PrimitiveVariableMap::iterator cIt = image->variables.find( channelName );
if ( cIt != image->variables.end() )
{
if ( !runTimeCast< FloatVectorData >( cIt->second.data ) )
{
throw InvalidArgumentException(( boost::format( "PointRepulsionOp: ImagePrimitive channel '%s' must be of type FloatVectorData" ) % channelName ).str() );
}
}
else
{
throw InvalidArgumentException(( boost::format( "PointRepulsionOp: ImagePrimitive channel '%s' not found" ) % channelName ).str() );
}
const PrimitiveVariable &densityPrimVar = cIt->second;

ImagePrimitiveEvaluatorPtr imageEvaluator = new ImagePrimitiveEvaluator( image );
PrimitiveEvaluator::ResultPtr imageResult = imageEvaluator->createResult();

MeshPrimitiveEvaluatorPtr meshEvaluator = new MeshPrimitiveEvaluator( mesh );
PrimitiveEvaluator::ResultPtr meshResult = meshEvaluator->createResult();


/// Convert density image texture, so that values of pixels with the original density channel
/// represent "number of points per unit area".
int height = image->getDisplayWindow().max.y - image->getDisplayWindow().min.y + 1;
int width = image->getDisplayWindow().max.x - image->getDisplayWindow().min.x + 1;

if ( width == 0 || height == 0 )
{
throw InvalidArgumentException( "PointRepulsionOp: ImagePrimitive has zero area" );
}

float du = 1.0f / width;
float dv = 1.0f / height;

float textureArea = 0.0f;
for ( int y = 0; y < height; y++ )
{
for ( int x = 0; x < width; x++ )
{
//// Get point at center of pixel
bool found = imageEvaluator->pointAtPixel( V2i( x, y ), imageResult );
if ( found )
{
V2f topLeft = imageResult->uv() + V2f( -du / 2.0f, -dv / 2.0f );
V2f topRight = imageResult->uv() + V2f( du / 2.0f, -dv / 2.0f );
V2f bottomRight = imageResult->uv() + V2f( du / 2.0f, dv / 2.0f );
V2f bottomLeft = imageResult->uv() + V2f( -du / 2.0f, dv / 2.0f );

std::vector<V2f> pixelCornersUV;
pixelCornersUV.push_back( topLeft );
pixelCornersUV.push_back( topRight );
pixelCornersUV.push_back( bottomRight );
pixelCornersUV.push_back( bottomLeft );

std::vector<V3f> pixelCornersWorld;

for ( unsigned c = 0; c < 4; c++ )
{
found = meshEvaluator->pointAtUV( pixelCornersUV[c], meshResult );

if ( found )
{
pixelCornersWorld.push_back( meshResult->point() );
}
}

if ( pixelCornersWorld.size() == 4 )
{
/// \todo optimise
imageEvaluator->pointAtPixel( V2i( x, y ), imageResult );
float density = imageResult->floatPrimVar( densityPrimVar );

textureArea += density * triangleArea( pixelCornersWorld[0], pixelCornersWorld[1], pixelCornersWorld[2] ) ;
textureArea += density * triangleArea( pixelCornersWorld[0], pixelCornersWorld[2], pixelCornersWorld[3] );
}
else if ( pixelCornersWorld.size() == 3 )
{
/// \todo optimise
imageEvaluator->pointAtPixel( V2i( x, y ), imageResult );
float density = imageResult->floatPrimVar( densityPrimVar );

textureArea += density * triangleArea( pixelCornersWorld[0], pixelCornersWorld[1], pixelCornersWorld[2] );
}
}
}
}
FloatVectorDataPtr densityData = runTimeCast< FloatVectorData >( densityPrimVar.data );
assert( densityData );
int dataOffset = 0;
for ( int y = 0; y < height; y++ )
{
for ( int x = 0; x < width; x++ )
{
densityData->writable()[ dataOffset ++ ] *= ( float )numPoints / textureArea;
}
}

std::vector<float> originalDensities( numPoints );
std::vector<float> currentDensities( numPoints );
std::vector<Imath::V3f> forces( numPoints );
std::vector<float> radii( numPoints );
std::vector<Imath::V3f> oldPoints( numPoints );
std::vector<Imath::Box3f> bounds( numPoints );

float lastEnergy = std::numeric_limits<float>::max();

Rand48 generator( 1 );

for ( int i = 0; i < numIterations; ++i )
{
assert( points.size() == originalDensities.size() );
assert( points.size() == currentDensities.size() );
assert( points.size() == forces.size() );
assert( points.size() == radii.size() );
assert( points.size() == oldPoints.size() );
assert( points.size() == bounds.size() );

// Snap points to mesh, and calculate new densities
getNearestPointsAndDensities( imageEvaluator, densityPrimVar, meshEvaluator, sIt->second, tIt->second, points, currentDensities );

if ( i == 0 )
{
std::copy( currentDensities.begin(), currentDensities.end(), originalDensities.begin() );
}

/// Update radii, bounds, and force accumulator
for ( PointArray::size_type p = 0; p < numPoints; p++ )
{
float pointsPerUnitArea = originalDensities[ p ];

/// \todo More accurately determine the minimum permissible value for "pointsPerUnitArea"
float areaPerPoint = 1.0f / std::max( 0.01f, pointsPerUnitArea );

assert( p < radii.size() );

/// pi * r * r = area
/// Compensate for the fact that even at the densest possible packing (hexagonal), we only get pi/sqrt(12) ( ~ 0.9 ) efficiency,
/// by making each "circle" slightly larger by sqrt(12)/pi
radii[p] = sqrt( areaPerPoint / M_PI ) * sqrt( 12.0f ) / M_PI;

assert( p < radii.size() );
bounds[p] = Imath::Box3f(
Imath::V3f( points[p] - Imath::V3f( radii[p], radii[p], radii[p] ) ),
Imath::V3f( points[p] + Imath::V3f( radii[p], radii[p], radii[p] ) )
);

/// Zero force accumulator
forces[p] = V3f( 0.0 );
}

calculateForces( points, radii, bounds, forces, generator, originalDensities, textureArea / ( float )numPoints );

std::copy( points.begin(), points.end(), oldPoints.begin() );

float totalEnergy = 0.0f;
for ( PointArray::size_type p = 0; p < numPoints; p++ )
{
totalEnergy += forces[p].length();

/// Advect point by force applied to it
points[p] += forces[p] * magnitude;
}

// Snap points back to mesh, and calculate new densities
getNearestPointsAndDensities( imageEvaluator, densityPrimVar, meshEvaluator, sIt->second, tIt->second, points, currentDensities );

totalEnergy = 0.0f;
for ( PointArray::size_type p = 0; p < numPoints; p++ )
{
float denom = std::max( originalDensities[p], currentDensities[p] );
float scale = 1.0f;
if ( denom > 1.0e-6f )
{
scale = fabsf( originalDensities[p] - currentDensities[p] ) / denom;
}
forces[p] *= 1.0f - scale;

if ( weights )
{
forces[p] *= weights->readable()[ p ];
}

totalEnergy += forces[p].length();

/// Advect point by force applied to it
points[p] = oldPoints[p] + forces[p] * magnitude;
}

assert( totalEnergy >= 0.0f );

msg( Msg::Info, "PointRepulsionOp", boost::format( "Residual error after iteration %s : %s " ) % i % totalEnergy );

if ( totalEnergy > lastEnergy )
{
float percentageIncrease = ( totalEnergy / lastEnergy - 1.0f ) * 100.0f;

if ( percentageIncrease > 1.0 )
{
msg( Msg::Warning, "PointRepulsionOp", boost::format( "Residual error increased by %f%% during iteration %s, consider decreasing magnitude parameter " ) % ( percentageIncrease ) % i );
}
}

if ( totalEnergy < 1.e-6f )
{
break;
}

lastEnergy = totalEnergy;
}

getNearestPointsAndDensities( imageEvaluator, densityPrimVar, meshEvaluator, sIt->second, tIt->second, points, currentDensities );

if ( pointsPrimitive->variables.find( "width" ) == pointsPrimitive->variables.end() )
{
for ( PointArray::size_type p = 0; p < numPoints; p++ )
{
radii[p] *= 2.0; /// now want to interpret as "width" (diameter)
}
pointsPrimitive->variables["width"] = PrimitiveVariable( PrimitiveVariable::Vertex, new FloatVectorData( radii ) );
}

/// Update s and t, if necessary
bool pointsPrimitiveHasS = pointsPrimitive->variables.find( "s" ) != pointsPrimitive->variables.end();
bool pointsPrimitiveHasT = pointsPrimitive->variables.find( "t" ) != pointsPrimitive->variables.end();

if ( pointsPrimitiveHasS || pointsPrimitiveHasT )
{
FloatVectorDataPtr sData = 0;
if ( pointsPrimitiveHasS )
{
sData = new FloatVectorData();
sData->writable().resize( numPoints );
}
FloatVectorDataPtr tData = 0;
if ( pointsPrimitiveHasT )
{
tData = new FloatVectorData();
tData->writable().resize( numPoints );
}

assert( sData || tData );

for ( PointArray::size_type p = 0; p < numPoints; p++ )
{
bool found = meshEvaluator->closestPoint( points[p], meshResult );
assert( found );
( void ) found;

if ( sData )
{
assert( p < sData->readable().size() );
sData->writable()[p] = meshResult->uv().x;
}
if ( tData )
{
assert( p < tData->readable().size() );
tData->writable()[p] = meshResult->uv().y;
}
}

if ( sData )
{
pointsPrimitive->variables["s"] = PrimitiveVariable( PrimitiveVariable::Varying, sData );
}
if ( tData )
{
pointsPrimitive->variables["t"] = PrimitiveVariable( PrimitiveVariable::Varying, tData );
}
}
}

Change log

r3493 by john.imageengine on Jun 17, 2010   Diff
Fixes crash caused by not maintaining
ownership of copied object.
Go to: 
Project members, sign in to write a code review

Older revisions

r3016 by lucio.imageengine on Mar 9, 2010   Diff
Changing Op classes by using raw
pointers whenever possible.
r2933 by john.imageengine on Feb 15, 2010   Diff
Removed name() field from Paramerised
classes - it was pretty much just
duplicating typeName() but in a
useless way, and introducing a bunch
of ambiguity.
r2354 by mark.imageengine on Apr 22, 2009   Diff
Updated RunTimeTyped to keep track of
base classes, too, and allow basic
queries of the type registry
All revisions of this file

File info

Size: 22114 bytes, 684 lines
Powered by Google Project Hosting