Revision: 57291
http://sourceforge.net/p/brlcad/code/57291
Author: r_weiss
Date: 2013-08-29 22:55:56 +0000 (Thu, 29 Aug 2013)
Log Message:
-----------
Changes to 'libbrep' function 'pullback_samples_from_closed_surface' to correct
valgrind warnings that uninitialized memory was being accessed and also fix
intermittent seg-faults. The problem was sometimes when 'prev_pt' was used it
was undefined. Additional code was added to help debugging. These problems were
encountered using the 'step-g' converter. More testing is needed.
Modified Paths:
--------------
brlcad/trunk/src/libbrep/PullbackCurve.cpp
Modified: brlcad/trunk/src/libbrep/PullbackCurve.cpp
===================================================================
--- brlcad/trunk/src/libbrep/PullbackCurve.cpp 2013-08-29 22:51:51 UTC (rev
57290)
+++ brlcad/trunk/src/libbrep/PullbackCurve.cpp 2013-08-29 22:55:56 UTC (rev
57291)
@@ -45,7 +45,6 @@
#define RANGE_LO 0.45
#define UNIVERSAL_SAMPLE_COUNT 1001
-
/* FIXME: duplicated with opennurbs_ext.cpp */
class BSpline
{
@@ -58,7 +57,6 @@
ON_2dPointArray controls;
};
-
bool
isFlat(const ON_2dPoint& p1, const ON_2dPoint& m, const ON_2dPoint& p2, double
flatness)
{
@@ -931,6 +929,7 @@
return;
const ON_Curve* curve = data->curve;
+
if (!curve)
return;
@@ -939,9 +938,17 @@
return;
ON_2dPointArray *samples = new ON_2dPointArray();
+
size_t numKnots = curve->SpanCount();
double *knots = new double[numKnots + 1];
+ ON_2dPoint lastgoodpoint;
+ ON_2dPoint lastbadpoint;
+ ON_2dPoint workingpoint;
+ bool lastgoodpoint_set = false;
+ bool lastbadpoint_set = false;
+ bool workingpoint_set = false;
+
curve->GetSpanVector(knots);
size_t istart = 0;
@@ -960,14 +967,10 @@
knots[++istop] = s;
}
- //TODO: remove debugging code
- //std::cerr << "t - " << t << " istart - " << istart << "knots[istart] - "
<< knots[istart] << std::endl;
- //std::cerr << "s - " << s << " istop - " << istop << "knots[istop] - " <<
knots[istop] << std::endl;
-
size_t samplesperknotinterval;
size_t degree = curve->Degree();
- if (degree > 1) {
+ if (degree == 1) {
samplesperknotinterval = 3 * degree;
} else {
samplesperknotinterval = 18 * degree;
@@ -988,8 +991,17 @@
size_t i;
for (i = istart; (i <= (numKnots / 2)) && (i <= istop); ++i) {
- if (i > 0) {
+ if (i > istart) {
double delta = (knots[i] - knots[i - 1]) /
(double)samplesperknotinterval;
+ if (!toUV(*data, prev_pt, knots[i - 1], PBC_FROM_OFFSET)) {
+ std::cout << "prev_pt1 failed" << std::endl;
+ } else {
+ lastgoodpoint = prev_pt;
+ samples->Append(prev_pt);
+ lastgoodpoint_set = true;
+ lastbadpoint_set = false;
+ workingpoint_set = false;
+ }
for (size_t j = 1; j < samplesperknotinterval;) {
if (toUV(*data, pt, knots[i - 1] + j * delta, PBC_FROM_OFFSET))
{
pt = resolve_seam_point_from_prev(surf, pt, prev_pt);
@@ -1001,9 +1013,6 @@
#ifdef SHOW_UNUSED
double lastgood = 0.0, lastbad = 0.0;
#endif
- ON_2dPoint lastgoodpoint;
- ON_2dPoint lastbadpoint;
- ON_2dPoint workingpoint;
if (dot < dottol) {
double step = delta;
double at = knots[i - 1] + j * delta;
@@ -1014,8 +1023,10 @@
lastbad = at;
#endif
lastbadpoint = workingpoint;
+ lastbadpoint_set = workingpoint_set;
at = at - step;
if (toUV(*data, workingpoint, at,
PBC_FROM_OFFSET)) {
+ workingpoint_set = true;
dir = workingpoint - prev_pt;
dir.Unitize();
dot = prev_dir * dir;
@@ -1025,8 +1036,10 @@
lastgood = at;
#endif
lastgoodpoint = workingpoint;
+ lastgoodpoint_set = workingpoint_set;
at = at + step;
if (toUV(*data, workingpoint, at,
PBC_FROM_OFFSET)) {
+ workingpoint_set = true;
dir = workingpoint - prev_pt;
dir.Unitize();
dot = prev_dir * dir;
@@ -1038,19 +1051,30 @@
lastbad = at;
#endif
lastbadpoint = workingpoint;
+ lastbadpoint_set = workingpoint_set;
} else {
#ifdef SHOW_UNUSED
lastgood = at;
#endif
lastgoodpoint = workingpoint;
+ lastgoodpoint_set = workingpoint_set;
}
- samples->Append(lastgoodpoint);
- data->segments.push_back(samples);
- samples = new ON_2dPointArray();
- samples->Append(lastbadpoint);
+ if (lastgoodpoint_set) {
+ samples->Append(lastgoodpoint);
+ data->segments.push_back(samples);
+ samples = new ON_2dPointArray();
+ }
- std::cout << "finalgoodpt - " << lastgoodpoint.x
<< "," << lastgoodpoint.y << std::endl;
- std::cout << "finalbadpt - " << lastbadpoint.x <<
"," << lastbadpoint.y << std::endl;
+ if (lastgoodpoint_set) {
+ std::cout << "finalgoodpt1 - " <<
lastgoodpoint.x << "," << lastgoodpoint.y << std::endl;
+ } else {
+ std::cout << "finalgoodpt1 - unknown" <<
std::endl;
+ }
+ if (lastbadpoint_set) {
+ std::cout << "finalbadpt1 - " <<
lastbadpoint.x << "," << lastbadpoint.y << std::endl;
+ } else {
+ std::cout << "finalbadpt1 - unknown" <<
std::endl;
+ }
}
}
samples->Append(pt);
@@ -1064,7 +1088,7 @@
j++;
}
}
- } /* i > 0 */
+ } /* i > istart */
if (toUV(*data, pt, knots[i], PBC_FROM_OFFSET)) {
if ((i == istart) && (i < numKnots)) {
@@ -1090,8 +1114,19 @@
}
}
- for (; (i <= numKnots) && (i <= istop); ++i) {
+ has_dir = false;
+ has_prev_dir = false;
+ for (; (i > 1) && (i <= numKnots) && (i <= istop); ++i) {
double delta = (knots[i] - knots[i - 1]) /
(double)samplesperknotinterval;
+ if (!toUV(*data, prev_pt, knots[i - 1], -PBC_FROM_OFFSET)) {
+ std::cout << "prev_pt2 failed" << std::endl;
+ } else {
+ lastgoodpoint = prev_pt;
+ samples->Append(prev_pt);
+ lastgoodpoint_set = true;
+ lastbadpoint_set = false;
+ workingpoint_set = false;
+ }
for (size_t j = 1; j < samplesperknotinterval;) {
if (toUV(*data, pt, knots[i - 1] + j * delta, -PBC_FROM_OFFSET)) {
pt = resolve_seam_point_from_prev(surf, pt, prev_pt);
@@ -1103,9 +1138,6 @@
#ifdef SHOW_UNUSED
double lastgood = 0.0, lastbad = 0.0;
#endif
- ON_2dPoint lastgoodpoint;
- ON_2dPoint lastbadpoint;
- ON_2dPoint workingpoint;
//std::cout << "dot - " << dot << std::endl;
if (dot < dottol) {
double step = delta;
@@ -1117,8 +1149,10 @@
lastbad = at;
#endif
lastbadpoint = workingpoint;
+ lastbadpoint_set = workingpoint_set;
at = at - step;
if (toUV(*data, workingpoint, at,
-PBC_FROM_OFFSET)) {
+ workingpoint_set = true;
dir = workingpoint - prev_pt;
dir.Unitize();
dot = prev_dir * dir;
@@ -1128,8 +1162,10 @@
lastgood = at;
#endif
lastgoodpoint = workingpoint;
+ lastgoodpoint_set = workingpoint_set;
at = at + step;
if (toUV(*data, workingpoint, at,
-PBC_FROM_OFFSET)) {
+ workingpoint_set = true;
dir = workingpoint - prev_pt;
dir.Unitize();
dot = prev_dir * dir;
@@ -1141,19 +1177,30 @@
lastbad = at;
#endif
lastbadpoint = workingpoint;
+ lastbadpoint_set = workingpoint_set;
} else {
#ifdef SHOW_UNUSED
lastgood = at;
#endif
lastgoodpoint = workingpoint;
+ lastgoodpoint_set = workingpoint_set;
}
- samples->Append(lastgoodpoint);
- data->segments.push_back(samples);
- samples = new ON_2dPointArray();
- samples->Append(lastbadpoint);
+ if (lastgoodpoint_set) {
+ samples->Append(lastgoodpoint);
+ data->segments.push_back(samples);
+ samples = new ON_2dPointArray();
+ }
- std::cout << "finalgoodpt - " << lastgoodpoint.x <<
"," << lastgoodpoint.y << std::endl;
- std::cout << "finalbadpt - " << lastbadpoint.x << ","
<< lastbadpoint.y << std::endl;
+ if (lastgoodpoint_set) {
+ std::cout << "finalgoodpt2 - " << lastgoodpoint.x
<< "," << lastgoodpoint.y << std::endl;
+ } else {
+ std::cout << "finalgoodpt2 - unknown" << std::endl;
+ }
+ if (lastbadpoint_set) {
+ std::cout << "finalbadpt2 - " << lastbadpoint.x <<
"," << lastbadpoint.y << std::endl;
+ } else {
+ std::cout << "finalbadpt2 - unknown" << std::endl;
+ }
}
}
samples->Append(pt);
@@ -1182,12 +1229,14 @@
}
delete [] knots;
- if (samples != NULL)
+
+ if (samples != NULL) {
data->segments.push_back(samples);
+ }
return;
}
-
+
PBCData *
pullback_samples(const brlcad::SurfaceTree* surfacetree,
const ON_Curve* curve,
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits