Add a configuration item to specify the maximum number of piecewise

linear segments to generate, irrespective of the chord tolerance.
That used to be hard-coded, and it needs to be small enough to
avoid lags while working interactively, but I also need to export
fine geometry.

[git-p4: depot-paths = "//depot/solvespace/": change = 1857]
solver
Jonathan Westhues 2008-02-12 05:00:26 -08:00
parent ea7ffd4b2a
commit c42033d123
6 changed files with 62 additions and 33 deletions

View File

@ -157,7 +157,8 @@ void Entity::BezierPwl(double ta, double tb,
double tol = SS.chordTol/SS.GW.scale; double tol = SS.chordTol/SS.GW.scale;
if((tb - ta) < 0.01 || d < tol) { double step = 1.0/SS.maxSegments;
if((tb - ta) < step || d < tol) {
LineDrawOrGetDistanceOrEdge(pa, pb); LineDrawOrGetDistanceOrEdge(pa, pb);
} else { } else {
double tm = (ta + tb) / 2; double tm = (ta + tb) / 2;

View File

@ -39,6 +39,8 @@ void SolveSpace::Init(char *cmdLine) {
lightDir[1].z = CnfThawFloat( 0.0f, "LightDir_1_Forward" ); lightDir[1].z = CnfThawFloat( 0.0f, "LightDir_1_Forward" );
// Chord tolerance // Chord tolerance
chordTol = CnfThawFloat(2.0f, "ChordTolerance"); chordTol = CnfThawFloat(2.0f, "ChordTolerance");
// Max pwl segments to generate
maxSegments = CnfThawDWORD(40, "MaxSegments");
// View units // View units
viewUnits = (Unit)CnfThawDWORD((DWORD)UNIT_MM, "ViewUnits"); viewUnits = (Unit)CnfThawDWORD((DWORD)UNIT_MM, "ViewUnits");
// Camera tangent (determines perspective) // Camera tangent (determines perspective)
@ -95,6 +97,8 @@ void SolveSpace::Exit(void) {
CnfFreezeFloat((float)lightDir[1].z, "LightDir_1_Forward"); CnfFreezeFloat((float)lightDir[1].z, "LightDir_1_Forward");
// Chord tolerance // Chord tolerance
CnfFreezeFloat((float)chordTol, "ChordTolerance"); CnfFreezeFloat((float)chordTol, "ChordTolerance");
// Max pwl segments to generate
CnfFreezeDWORD((DWORD)maxSegments, "MaxSegments");
// Display/entry units // Display/entry units
CnfFreezeDWORD((DWORD)viewUnits, "ViewUnits"); CnfFreezeDWORD((DWORD)viewUnits, "ViewUnits");
// Camera tangent (determines perspective) // Camera tangent (determines perspective)
@ -129,7 +133,7 @@ int SolveSpace::CircleSides(double r) {
double tol = chordTol/GW.scale; double tol = chordTol/GW.scale;
int n = 3 + (int)(PI/sqrt(2*tol/r)); int n = 3 + (int)(PI/sqrt(2*tol/r));
return max(7, min(n, 200)); return max(7, min(n, maxSegments));
} }
char *SolveSpace::MmToString(double v) { char *SolveSpace::MmToString(double v) {

View File

@ -366,6 +366,7 @@ public:
Vector lightDir[2]; Vector lightDir[2];
double lightIntensity[2]; double lightIntensity[2];
double chordTol; double chordTol;
int maxSegments;
double cameraTangent; double cameraTangent;
DWORD edgeColor; DWORD edgeColor;
float exportScale; float exportScale;

View File

@ -545,31 +545,37 @@ void TextWindow::ScreenChangeColor(int link, DWORD v) {
SS.TW.edit.meaning = EDIT_COLOR; SS.TW.edit.meaning = EDIT_COLOR;
SS.TW.edit.i = v; SS.TW.edit.i = v;
} }
void TextWindow::ScreenChangeChordTolerance(int link, DWORD v) {
char str[1024];
sprintf(str, "%.2f", SS.chordTol);
ShowTextEditControl(37, 3, str);
SS.TW.edit.meaning = EDIT_CHORD_TOLERANCE;
}
void TextWindow::ScreenChangeCameraTangent(int link, DWORD v) {
char str[1024];
sprintf(str, "%.3f", 1000*SS.cameraTangent);
ShowTextEditControl(43, 3, str);
SS.TW.edit.meaning = EDIT_CAMERA_TANGENT;
}
void TextWindow::ScreenChangeEdgeColor(int link, DWORD v) { void TextWindow::ScreenChangeEdgeColor(int link, DWORD v) {
char str[1024]; char str[1024];
sprintf(str, "%.3f, %.3f, %.3f", sprintf(str, "%.3f, %.3f, %.3f",
REDf(SS.edgeColor), GREENf(SS.edgeColor), BLUEf(SS.edgeColor)); REDf(SS.edgeColor), GREENf(SS.edgeColor), BLUEf(SS.edgeColor));
ShowTextEditControl(49, 3, str); ShowTextEditControl(37, 3, str);
SS.TW.edit.meaning = EDIT_EDGE_COLOR; SS.TW.edit.meaning = EDIT_EDGE_COLOR;
} }
void TextWindow::ScreenChangeChordTolerance(int link, DWORD v) {
char str[1024];
sprintf(str, "%.2f", SS.chordTol);
ShowTextEditControl(43, 3, str);
SS.TW.edit.meaning = EDIT_CHORD_TOLERANCE;
}
void TextWindow::ScreenChangeMaxSegments(int link, DWORD v) {
char str[1024];
sprintf(str, "%d", SS.maxSegments);
ShowTextEditControl(47, 3, str);
SS.TW.edit.meaning = EDIT_MAX_SEGMENTS;
}
void TextWindow::ScreenChangeCameraTangent(int link, DWORD v) {
char str[1024];
sprintf(str, "%.3f", 1000*SS.cameraTangent);
ShowTextEditControl(53, 3, str);
SS.TW.edit.meaning = EDIT_CAMERA_TANGENT;
}
void TextWindow::ScreenChangeExportScale(int link, DWORD v) { void TextWindow::ScreenChangeExportScale(int link, DWORD v) {
char str[1024]; char str[1024];
sprintf(str, "%.3f", (double)SS.exportScale); sprintf(str, "%.3f", (double)SS.exportScale);
ShowTextEditControl(55, 3, str); ShowTextEditControl(59, 3, str);
SS.TW.edit.meaning = EDIT_EXPORT_SCALE; SS.TW.edit.meaning = EDIT_EXPORT_SCALE;
} }
void TextWindow::ShowConfiguration(void) { void TextWindow::ShowConfiguration(void) {
@ -597,12 +603,22 @@ void TextWindow::ShowConfiguration(void) {
SS.lightIntensity[i], i, &ScreenChangeLightIntensity); SS.lightIntensity[i], i, &ScreenChangeLightIntensity);
} }
Printf(false, "");
Printf(false, "%Ft edge color r,g,b (0,0,0 for no edges)%E");
Printf(false, "%Ba %@, %@, %@ %Fl%Ll%f%D[change]%E",
REDf(SS.edgeColor), GREENf(SS.edgeColor), BLUEf(SS.edgeColor),
&ScreenChangeEdgeColor, 0);
Printf(false, ""); Printf(false, "");
Printf(false, "%Ft chord tolerance (in screen pixels)%E"); Printf(false, "%Ft chord tolerance (in screen pixels)%E");
Printf(false, "%Ba %2 %Fl%Ll%f%D[change]%E; now %d triangles", Printf(false, "%Ba %2 %Fl%Ll%f%D[change]%E; now %d triangles",
SS.chordTol, SS.chordTol,
&ScreenChangeChordTolerance, 0, &ScreenChangeChordTolerance, 0,
SS.GetGroup(SS.GW.activeGroup)->runningMesh.l.n); SS.GetGroup(SS.GW.activeGroup)->runningMesh.l.n);
Printf(false, "%Ft max piecewise linear segments%E");
Printf(false, "%Ba %d %Fl%Ll%f[change]%E",
SS.maxSegments,
&ScreenChangeMaxSegments);
Printf(false, ""); Printf(false, "");
Printf(false, "%Ft perspective factor (0 for parallel)%E"); Printf(false, "%Ft perspective factor (0 for parallel)%E");
@ -610,12 +626,6 @@ void TextWindow::ShowConfiguration(void) {
SS.cameraTangent*1000, SS.cameraTangent*1000,
&ScreenChangeCameraTangent, 0); &ScreenChangeCameraTangent, 0);
Printf(false, "");
Printf(false, "%Ft edge color r,g,b (0,0,0 for no edges)%E");
Printf(false, "%Ba %@, %@, %@ %Fl%Ll%f%D[change]%E",
REDf(SS.edgeColor), GREENf(SS.edgeColor), BLUEf(SS.edgeColor),
&ScreenChangeEdgeColor, 0);
Printf(false, ""); Printf(false, "");
Printf(false, "%Ft export scale factor (1.0=mm, 25.4=inch)"); Printf(false, "%Ft export scale factor (1.0=mm, 25.4=inch)");
Printf(false, "%Ba %3 %Fl%Ll%f%D[change]%E", Printf(false, "%Ba %3 %Fl%Ll%f%D[change]%E",
@ -798,6 +808,11 @@ void TextWindow::EditControlDone(char *s) {
SS.GenerateAll(0, INT_MAX); SS.GenerateAll(0, INT_MAX);
break; break;
} }
case EDIT_MAX_SEGMENTS: {
SS.maxSegments = min(1000, max(7, atoi(s)));
SS.GenerateAll(0, INT_MAX);
break;
}
case EDIT_CAMERA_TANGENT: { case EDIT_CAMERA_TANGENT: {
SS.cameraTangent = (min(2, max(0, atof(s))))/1000.0; SS.cameraTangent = (min(2, max(0, atof(s))))/1000.0;
InvalidateGraphics(); InvalidateGraphics();

View File

@ -706,7 +706,8 @@ void TtfFont::BezierPwl(double ta, double tb, Vector p0, Vector p1, Vector p2) {
double tol = SS.chordTol/SS.GW.scale; double tol = SS.chordTol/SS.GW.scale;
if((tb - ta) < 0.01 || pm.DistanceToLine(pa, pb.Minus(pa)) < tol) { double step = 1.0/SS.maxSegments;
if((tb - ta) < step || pm.DistanceToLine(pa, pb.Minus(pa)) < tol) {
Entity *e = SS.GetEntity(entity); Entity *e = SS.GetEntity(entity);
e->LineDrawOrGetDistanceOrEdge(pa, pb); e->LineDrawOrGetDistanceOrEdge(pa, pb);
} else { } else {

27
ui.h
View File

@ -63,21 +63,27 @@ public:
ShownState shown; ShownState shown;
static const int EDIT_NOTHING = 0; static const int EDIT_NOTHING = 0;
// For multiple groups
static const int EDIT_TIMES_REPEATED = 1; static const int EDIT_TIMES_REPEATED = 1;
static const int EDIT_GROUP_NAME = 2; static const int EDIT_GROUP_NAME = 2;
static const int EDIT_LIGHT_DIRECTION = 3; // For the configuraiton screen
static const int EDIT_LIGHT_INTENSITY = 4; static const int EDIT_LIGHT_DIRECTION = 10;
static const int EDIT_COLOR = 5; static const int EDIT_LIGHT_INTENSITY = 11;
static const int EDIT_CHORD_TOLERANCE = 6; static const int EDIT_COLOR = 12;
static const int EDIT_CAMERA_TANGENT = 7; static const int EDIT_CHORD_TOLERANCE = 13;
static const int EDIT_EDGE_COLOR = 8; static const int EDIT_MAX_SEGMENTS = 14;
static const int EDIT_EXPORT_SCALE = 9; static const int EDIT_CAMERA_TANGENT = 15;
static const int EDIT_EDGE_COLOR = 16;
static const int EDIT_EXPORT_SCALE = 17;
// For the helical sweep
static const int EDIT_HELIX_TURNS = 20; static const int EDIT_HELIX_TURNS = 20;
static const int EDIT_HELIX_PITCH = 21; static const int EDIT_HELIX_PITCH = 21;
static const int EDIT_HELIX_DRADIUS = 22; static const int EDIT_HELIX_DRADIUS = 22;
static const int EDIT_TTF_TEXT = 23; // For TTF text
static const int EDIT_STEP_DIM_FINISH = 30; static const int EDIT_TTF_TEXT = 30;
static const int EDIT_STEP_DIM_STEPS = 31; // For the step dimension screen
static const int EDIT_STEP_DIM_FINISH = 40;
static const int EDIT_STEP_DIM_STEPS = 41;
struct { struct {
int meaning; int meaning;
int i; int i;
@ -145,6 +151,7 @@ public:
static void ScreenChangeLightIntensity(int link, DWORD v); static void ScreenChangeLightIntensity(int link, DWORD v);
static void ScreenChangeColor(int link, DWORD v); static void ScreenChangeColor(int link, DWORD v);
static void ScreenChangeChordTolerance(int link, DWORD v); static void ScreenChangeChordTolerance(int link, DWORD v);
static void ScreenChangeMaxSegments(int link, DWORD v);
static void ScreenChangeCameraTangent(int link, DWORD v); static void ScreenChangeCameraTangent(int link, DWORD v);
static void ScreenChangeEdgeColor(int link, DWORD v); static void ScreenChangeEdgeColor(int link, DWORD v);
static void ScreenChangeExportScale(int link, DWORD v); static void ScreenChangeExportScale(int link, DWORD v);