@@ -57,6 +57,33 @@ namespace pov
5757* Local preprocessor defines
5858******************************************************************************/
5959
60+ struct ISO_Max_Gradient
61+ {
62+ DBL max_gradient, gradient;
63+ DBL eval_max, eval_cnt, eval_gradient_sum, eval_var;
64+ bool reported;
65+
66+ ISO_Max_Gradient () :
67+ max_gradient (0.0 ),
68+ gradient (0.0 ),
69+ eval_max (0.0 ),
70+ eval_cnt (0.0 ),
71+ eval_gradient_sum (0.0 ),
72+ reported (false ),
73+ mRefCounter (0 )
74+ {}
75+
76+ bool IsShared () const { return mRefCounter > 1 ; }
77+
78+ private:
79+ mutable size_t mRefCounter ;
80+ friend void intrusive_ptr_add_ref (ISO_Max_Gradient* f);
81+ friend void intrusive_ptr_release (ISO_Max_Gradient* f);
82+ };
83+
84+ inline void intrusive_ptr_add_ref (ISO_Max_Gradient* f) { ++f->mRefCounter ; }
85+ inline void intrusive_ptr_release (ISO_Max_Gradient* f) { if (!(--f->mRefCounter )) delete f; }
86+
6087
6188/* ****************************************************************************
6289*
@@ -557,19 +584,12 @@ IsoSurface::IsoSurface() :
557584 eval_param[2 ] = 0.0 ; // 0.99; // not necessary
558585 eval = false ;
559586 closed = true ;
560- isCopy = false ;
561587
562588 max_gradient = 1.1 ;
563589 gradient = 0.0 ;
564590 threshold = 0.0 ;
565591
566- mginfo = reinterpret_cast <ISO_Max_Gradient *>(POV_MALLOC (sizeof (ISO_Max_Gradient), " isosurface max_gradient info" ));
567- mginfo->refcnt = 1 ;
568- mginfo->max_gradient = 0.0 ;
569- mginfo->gradient = 0.0 ; // not really necessary yet [trf]
570- mginfo->eval_max = 0.0 ;
571- mginfo->eval_cnt = 0.0 ;
572- mginfo->eval_gradient_sum = 0.0 ;
592+ mginfo = intrusive_ptr<ISO_Max_Gradient>(new ISO_Max_Gradient ());
573593}
574594
575595
@@ -610,10 +630,6 @@ ObjectPtr IsoSurface::Copy()
610630 New->Trans = Copy_Transform (Trans);
611631
612632 New->mginfo = mginfo;
613- New->mginfo ->refcnt ++;
614-
615- // mark it as copy for use by max_gradient warning code
616- New->isCopy = true ;
617633
618634 New->positivePolarity = positivePolarity;
619635
@@ -651,8 +667,6 @@ ObjectPtr IsoSurface::Copy()
651667
652668IsoSurface::~IsoSurface ()
653669{
654- if (--mginfo->refcnt == 0 )
655- POV_FREE (mginfo);
656670 delete Function;
657671}
658672
@@ -692,60 +706,63 @@ void IsoSurface::DispatchShutdownMessages(GenericMessenger& messenger)
692706 mginfo->gradient = max (gradient, mginfo->gradient );
693707 mginfo->max_gradient = max ((DBL)temp_max_gradient, mginfo->max_gradient );
694708
695- if (isCopy == false )
709+ if (mginfo-> IsShared () )
696710 {
697- const FunctionSourceInfo* fnInfo = Function->GetSourceInfo ();
711+ // Other instances shall take care of reporting the max gradient.
712+ mginfo.reset ();
713+ return ;
714+ }
715+
716+ const FunctionSourceInfo* fnInfo = Function->GetSourceInfo ();
698717
699- if (fnInfo != NULL )
718+ if (fnInfo != NULL )
719+ {
720+ if (eval == false )
700721 {
701- if (eval == false )
722+ // Only show the warning if necessary!
723+ // BTW, not being too picky here is a feature and not a bug ;-) [trf]
724+ if ((mginfo->gradient > EPSILON) && (mginfo->max_gradient > EPSILON))
702725 {
703- // Only show the warning if necessary!
704- // BTW, not being too picky here is a feature and not a bug ;-) [trf]
705- if ((mginfo->gradient > EPSILON) && (mginfo->max_gradient > EPSILON))
706- {
707- DBL diff = mginfo->max_gradient - mginfo->gradient ;
708- DBL prop = fabs (mginfo->max_gradient / mginfo->gradient );
726+ DBL diff = mginfo->max_gradient - mginfo->gradient ;
727+ DBL prop = fabs (mginfo->max_gradient / mginfo->gradient );
709728
710- if (((prop <= 0.9 ) && (diff <= -0.5 )) || (((prop <= 0.95 ) || (diff <= -0.1 )) && (mginfo->max_gradient < 10.0 )))
711- {
712- messenger.WarningAt (kWarningGeneral , fnInfo->filename , fnInfo->filepos .lineno , 0 , fnInfo->filepos .offset ,
713- " The maximum gradient found was %0.3f, but max_gradient of the\n "
714- " isosurface was set to %0.3f. The isosurface may contain holes!\n "
715- " Adjust max_gradient to get a proper rendering of the isosurface." ,
716- (float )(mginfo->gradient ),
717- (float )(mginfo->max_gradient ));
718- }
719- else if ((diff >= 10.0 ) || ((prop >= 1.1 ) && (diff >= 0.5 )))
720- {
721- messenger.WarningAt (kWarningGeneral , fnInfo->filename , fnInfo->filepos .lineno , 0 , fnInfo->filepos .offset ,
722- " The maximum gradient found was %0.3f, but max_gradient of\n "
723- " the isosurface was set to %0.3f. Adjust max_gradient to\n "
724- " get a faster rendering of the isosurface." ,
725- (float )(mginfo->gradient ),
726- (float )(mginfo->max_gradient ));
727- }
729+ if (((prop <= 0.9 ) && (diff <= -0.5 )) || (((prop <= 0.95 ) || (diff <= -0.1 )) && (mginfo->max_gradient < 10.0 )))
730+ {
731+ messenger.WarningAt (kWarningGeneral , fnInfo->filename , fnInfo->filepos .lineno , 0 , fnInfo->filepos .offset ,
732+ " The maximum gradient found was %0.3f, but max_gradient of the\n "
733+ " isosurface was set to %0.3f. The isosurface may contain holes!\n "
734+ " Adjust max_gradient to get a proper rendering of the isosurface." ,
735+ (float )(mginfo->gradient ),
736+ (float )(mginfo->max_gradient ));
728737 }
729- }
730- else
731- {
732- DBL diff = (mginfo->eval_max / max (mginfo->eval_max - mginfo->eval_var , EPSILON));
733-
734- if ((eval_param[0 ] > mginfo->eval_max ) || (eval_param[1 ] > diff))
738+ else if ((diff >= 10.0 ) || ((prop >= 1.1 ) && (diff >= 0.5 )))
735739 {
736- mginfo->eval_cnt = max (mginfo->eval_cnt , 1.0 ); // make sure it won't be zero
737-
738- messenger.InfoAt (fnInfo->filename , fnInfo->filepos .lineno , 0 , fnInfo->filepos .offset ,
739- " Evaluate found a maximum gradient of %0.3f and an average\n "
740- " gradient of %0.3f. The maximum gradient variation was %0.3f.\n " ,
741- (float )(mginfo->eval_max ),
742- (float )(mginfo->eval_gradient_sum / mginfo->eval_cnt ),
743- (float )(mginfo->eval_var ));
740+ messenger.WarningAt (kWarningGeneral , fnInfo->filename , fnInfo->filepos .lineno , 0 , fnInfo->filepos .offset ,
741+ " The maximum gradient found was %0.3f, but max_gradient of\n "
742+ " the isosurface was set to %0.3f. Adjust max_gradient to\n "
743+ " get a faster rendering of the isosurface." ,
744+ (float )(mginfo->gradient ),
745+ (float )(mginfo->max_gradient ));
744746 }
745747 }
746748 }
747- }
749+ else
750+ {
751+ DBL diff = (mginfo->eval_max / max (mginfo->eval_max - mginfo->eval_var , EPSILON));
748752
753+ if ((eval_param[0 ] > mginfo->eval_max ) || (eval_param[1 ] > diff))
754+ {
755+ mginfo->eval_cnt = max (mginfo->eval_cnt , 1.0 ); // make sure it won't be zero
756+
757+ messenger.InfoAt (fnInfo->filename , fnInfo->filepos .lineno , 0 , fnInfo->filepos .offset ,
758+ " Evaluate found a maximum gradient of %0.3f and an average\n "
759+ " gradient of %0.3f. The maximum gradient variation was %0.3f.\n " ,
760+ (float )(mginfo->eval_max ),
761+ (float )(mginfo->eval_gradient_sum / mginfo->eval_cnt ),
762+ (float )(mginfo->eval_var ));
763+ }
764+ }
765+ }
749766}
750767
751768/* ****************************************************************************
0 commit comments