|
@@ -15,6 +15,8 @@
|
|
|
#include "nurbsCurve.h"
|
|
#include "nurbsCurve.h"
|
|
|
#include "config_parametrics.h"
|
|
#include "config_parametrics.h"
|
|
|
|
|
|
|
|
|
|
+#include <indent.h>
|
|
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Statics
|
|
// Statics
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
@@ -26,20 +28,6 @@ static const LVecBase3f zero = LVecBase3f(0.0, 0.0, 0.0);
|
|
|
// used from time to time as an initializer.
|
|
// used from time to time as an initializer.
|
|
|
|
|
|
|
|
|
|
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
|
|
-// Function: Indent
|
|
|
|
|
-// Description: This function duplicates a similar function declared
|
|
|
|
|
-// in eggBasics.C. It prints a specified number of
|
|
|
|
|
-// spaces to indent each line of output.
|
|
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
|
|
-static ostream &
|
|
|
|
|
-Indent(ostream &out, int indent) {
|
|
|
|
|
- for (int i=0; i<indent; i++) {
|
|
|
|
|
- out << ' ';
|
|
|
|
|
- }
|
|
|
|
|
- return out;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: NurbsCurve::Constructor
|
|
// Function: NurbsCurve::Constructor
|
|
|
// Access: Public, Scheme
|
|
// Access: Public, Scheme
|
|
@@ -355,61 +343,60 @@ get_knot(int n) const {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-// Function: NurbsCurve::print
|
|
|
|
|
|
|
+// Function: NurbsCurve::write
|
|
|
// Access: Public, Scheme
|
|
// Access: Public, Scheme
|
|
|
// Description:
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
void NurbsCurve::
|
|
void NurbsCurve::
|
|
|
-print() const {
|
|
|
|
|
|
|
+write(ostream &out) const {
|
|
|
switch (get_curve_type()) {
|
|
switch (get_curve_type()) {
|
|
|
case PCT_T:
|
|
case PCT_T:
|
|
|
- cout << "Time-warping ";
|
|
|
|
|
|
|
+ out << "Time-warping ";
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case PCT_XYZ:
|
|
case PCT_XYZ:
|
|
|
- cout << "XYZ ";
|
|
|
|
|
|
|
+ out << "XYZ ";
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case PCT_HPR:
|
|
case PCT_HPR:
|
|
|
- cout << "HPR ";
|
|
|
|
|
|
|
+ out << "HPR ";
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
default:
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- cout << "NurbsCurve, order " << _order << ", " << get_num_cvs()
|
|
|
|
|
- << " CV's. t ranges from 0 to " << get_max_t() << ".\n";
|
|
|
|
|
|
|
+ out << "NurbsCurve, order " << _order << ", " << get_num_cvs()
|
|
|
|
|
+ << " CV's. t ranges from 0 to " << get_max_t() << ".\n";
|
|
|
|
|
|
|
|
- cout << "CV's:\n";
|
|
|
|
|
|
|
+ out << "CV's:\n";
|
|
|
int i;
|
|
int i;
|
|
|
for (i = 0; i < (int)_cvs.size(); i++) {
|
|
for (i = 0; i < (int)_cvs.size(); i++) {
|
|
|
LVecBase3f p = (const LVecBase3f &)_cvs[i]._p / _cvs[i]._p[3];
|
|
LVecBase3f p = (const LVecBase3f &)_cvs[i]._p / _cvs[i]._p[3];
|
|
|
- cout << i << ") " << p << ", weight " << _cvs[i]._p[3] << "\n";
|
|
|
|
|
|
|
+ out << i << ") " << p << ", weight " << _cvs[i]._p[3] << "\n";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- cout << "Knots: ";
|
|
|
|
|
|
|
+ out << "Knots: ";
|
|
|
for (i = 0; i < (int)_cvs.size()+_order; i++) {
|
|
for (i = 0; i < (int)_cvs.size()+_order; i++) {
|
|
|
- cout << " " << GetKnot(i);
|
|
|
|
|
|
|
+ out << " " << GetKnot(i);
|
|
|
}
|
|
}
|
|
|
- cout << "\n" << flush;
|
|
|
|
|
|
|
+ out << "\n";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-// Function: NurbsCurve::print_cv
|
|
|
|
|
|
|
+// Function: NurbsCurve::write_cv
|
|
|
// Access: Public, Scheme
|
|
// Access: Public, Scheme
|
|
|
// Description:
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
void NurbsCurve::
|
|
void NurbsCurve::
|
|
|
-print_cv(int n) const {
|
|
|
|
|
|
|
+write_cv(ostream &out, int n) const {
|
|
|
if (n < 0 || n >= (int)_cvs.size()) {
|
|
if (n < 0 || n >= (int)_cvs.size()) {
|
|
|
- cout << "No such CV: " << n << "\n";
|
|
|
|
|
|
|
+ out << "No such CV: " << n << "\n";
|
|
|
} else {
|
|
} else {
|
|
|
LVecBase3f p = (const LVecBase3f &)_cvs[n]._p / _cvs[n]._p[3];
|
|
LVecBase3f p = (const LVecBase3f &)_cvs[n]._p / _cvs[n]._p[3];
|
|
|
- cout << "CV " << n << ": " << p << ", weight "
|
|
|
|
|
- << _cvs[n]._p[3] << "\n";
|
|
|
|
|
|
|
+ out << "CV " << n << ": " << p << ", weight "
|
|
|
|
|
+ << _cvs[n]._p[3] << "\n";
|
|
|
}
|
|
}
|
|
|
- cout << flush;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -692,12 +679,12 @@ rebuild_curveseg(int rtype0, double t0, const LVecBase4f &v0,
|
|
|
// Returns true if the file is successfully written.
|
|
// Returns true if the file is successfully written.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
bool NurbsCurve::
|
|
bool NurbsCurve::
|
|
|
-write_egg(const char *filename) {
|
|
|
|
|
|
|
+write_egg(const char *filename, CoordinateSystem cs) {
|
|
|
const char *basename = strrchr(filename, '/');
|
|
const char *basename = strrchr(filename, '/');
|
|
|
basename = (basename==NULL) ? filename : basename+1;
|
|
basename = (basename==NULL) ? filename : basename+1;
|
|
|
|
|
|
|
|
ofstream out(filename, ios::app);
|
|
ofstream out(filename, ios::app);
|
|
|
- return write_egg(out, basename);
|
|
|
|
|
|
|
+ return write_egg(out, basename, cs);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
@@ -708,7 +695,7 @@ write_egg(const char *filename) {
|
|
|
// successfully written.
|
|
// successfully written.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
bool NurbsCurve::
|
|
bool NurbsCurve::
|
|
|
-write_egg(ostream &out, const char *basename) {
|
|
|
|
|
|
|
+write_egg(ostream &out, const char *basename, CoordinateSystem cs) {
|
|
|
if (get_name().empty()) {
|
|
if (get_name().empty()) {
|
|
|
// If we don't have a name, come up with one.
|
|
// If we don't have a name, come up with one.
|
|
|
int len = strlen(basename);
|
|
int len = strlen(basename);
|
|
@@ -738,7 +725,7 @@ write_egg(ostream &out, const char *basename) {
|
|
|
set_name(name);
|
|
set_name(name);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Output(out);
|
|
|
|
|
|
|
+ format_egg(out, cs, 0);
|
|
|
|
|
|
|
|
if (out) {
|
|
if (out) {
|
|
|
return true;
|
|
return true;
|
|
@@ -804,26 +791,59 @@ splice(double t, const NurbsCurve &other) {
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-// Function: NurbsCurve::Output
|
|
|
|
|
|
|
+// Function: NurbsCurve::format_egg
|
|
|
// Access: Public
|
|
// Access: Public
|
|
|
// Description: Formats the Nurbs curve for output to an Egg file.
|
|
// Description: Formats the Nurbs curve for output to an Egg file.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
void NurbsCurve::
|
|
void NurbsCurve::
|
|
|
-Output(ostream &out, int indent) const {
|
|
|
|
|
- Indent(out, indent)
|
|
|
|
|
|
|
+format_egg(ostream &out, CoordinateSystem cs, int indent_level) const {
|
|
|
|
|
+ if (cs == CS_default) {
|
|
|
|
|
+ cs = default_coordinate_system;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (cs != CS_invalid) {
|
|
|
|
|
+ indent(out, indent_level)
|
|
|
|
|
+ << "<CoordinateSystem> { ";
|
|
|
|
|
+ switch (cs) {
|
|
|
|
|
+ case CS_zup_right:
|
|
|
|
|
+ out << "Z-Up";
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case CS_yup_right:
|
|
|
|
|
+ out << "Y-Up";
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case CS_zup_left:
|
|
|
|
|
+ out << "Z-Up-Left";
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case CS_yup_left:
|
|
|
|
|
+ out << "Y-Up-Left";
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ out << " }\n\n";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ indent(out, indent_level)
|
|
|
<< "<VertexPool> " << get_name() << ".pool {\n";
|
|
<< "<VertexPool> " << get_name() << ".pool {\n";
|
|
|
|
|
|
|
|
int cv;
|
|
int cv;
|
|
|
for (cv = 0; cv < (int)_cvs.size(); cv++) {
|
|
for (cv = 0; cv < (int)_cvs.size(); cv++) {
|
|
|
- Indent(out, indent+2) << "<Vertex> " << cv << " { "
|
|
|
|
|
- << _cvs[cv]._p << " }\n";
|
|
|
|
|
|
|
+ indent(out, indent_level+2)
|
|
|
|
|
+ << "<Vertex> " << cv << " { " << _cvs[cv]._p << " }\n";
|
|
|
}
|
|
}
|
|
|
- Indent(out, indent) << "}\n";
|
|
|
|
|
|
|
+ indent(out, indent_level)
|
|
|
|
|
+ << "}\n";
|
|
|
|
|
|
|
|
- Indent(out, indent) << "<NURBSCurve> " << get_name() << " {\n";
|
|
|
|
|
|
|
+ indent(out, indent_level)
|
|
|
|
|
+ << "<NURBSCurve> " << get_name() << " {\n";
|
|
|
|
|
|
|
|
if (_curve_type!=PCT_NONE) {
|
|
if (_curve_type!=PCT_NONE) {
|
|
|
- Indent(out, indent+2) << "<Char*> type { ";
|
|
|
|
|
|
|
+ indent(out, indent_level+2)
|
|
|
|
|
+ << "<Char*> type { ";
|
|
|
switch (_curve_type) {
|
|
switch (_curve_type) {
|
|
|
case PCT_XYZ:
|
|
case PCT_XYZ:
|
|
|
out << "XYZ";
|
|
out << "XYZ";
|
|
@@ -840,35 +860,36 @@ Output(ostream &out, int indent) const {
|
|
|
out << " }\n";
|
|
out << " }\n";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Indent(out, indent+2) << "<Order> { " << _order << " }\n";
|
|
|
|
|
|
|
+ indent(out, indent_level+2) << "<Order> { " << _order << " }\n";
|
|
|
|
|
|
|
|
- Indent(out, indent+2) << "<Knots> {";
|
|
|
|
|
|
|
+ indent(out, indent_level+2) << "<Knots> {";
|
|
|
int k;
|
|
int k;
|
|
|
int num_knots = _cvs.size() + _order;
|
|
int num_knots = _cvs.size() + _order;
|
|
|
|
|
|
|
|
for (k = 0; k < num_knots; k++) {
|
|
for (k = 0; k < num_knots; k++) {
|
|
|
if (k%6 == 0) {
|
|
if (k%6 == 0) {
|
|
|
out << "\n";
|
|
out << "\n";
|
|
|
- Indent(out, indent+4);
|
|
|
|
|
|
|
+ indent(out, indent_level+4);
|
|
|
}
|
|
}
|
|
|
out << GetKnot(k) << " ";
|
|
out << GetKnot(k) << " ";
|
|
|
}
|
|
}
|
|
|
out << "\n";
|
|
out << "\n";
|
|
|
- Indent(out, indent+2) << "}\n";
|
|
|
|
|
|
|
+ indent(out, indent_level+2) << "}\n";
|
|
|
|
|
|
|
|
- Indent(out, indent+2) << "<VertexRef> {";
|
|
|
|
|
|
|
+ indent(out, indent_level+2) << "<VertexRef> {";
|
|
|
for (cv = 0; cv < (int)_cvs.size(); cv++) {
|
|
for (cv = 0; cv < (int)_cvs.size(); cv++) {
|
|
|
- if (cv%10 == 1) {
|
|
|
|
|
|
|
+ if (cv%10 == 0) {
|
|
|
out << "\n";
|
|
out << "\n";
|
|
|
- Indent(out, indent+3);
|
|
|
|
|
|
|
+ indent(out, indent_level+3);
|
|
|
}
|
|
}
|
|
|
out << " " << cv;
|
|
out << " " << cv;
|
|
|
}
|
|
}
|
|
|
out << "\n";
|
|
out << "\n";
|
|
|
- Indent(out, indent+4) << "<Ref> { " << get_name() << ".pool }\n";
|
|
|
|
|
- Indent(out, indent+2) << "}\n";
|
|
|
|
|
|
|
+ indent(out, indent_level+4)
|
|
|
|
|
+ << "<Ref> { " << get_name() << ".pool }\n";
|
|
|
|
|
+ indent(out, indent_level+2) << "}\n";
|
|
|
|
|
|
|
|
- Indent(out, indent) << "}\n";
|
|
|
|
|
|
|
+ indent(out, indent_level) << "}\n";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|