Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/parametrics/nurbsCurveInterface.cxx

Go to the documentation of this file.
00001 // Filename: nurbsCurveInterface.cxx
00002 // Created by:  drose (02Mar01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "nurbsCurveInterface.h"
00020 #include "parametricCurve.h"
00021 #include "config_parametrics.h"
00022 
00023 TypeHandle NurbsCurveInterface::_type_handle;
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: NurbsCurveInterface::set_cv_weight
00027 //       Access: Published
00028 //  Description: Sets the weight of the indicated CV without affecting
00029 //               its position in 3-d space.
00030 ////////////////////////////////////////////////////////////////////
00031 bool NurbsCurveInterface::
00032 set_cv_weight(int n, float w) {
00033   nassertr(n >= 0 && n < get_num_cvs(), false);
00034   LVecBase4f cv = get_cv(n);
00035   if (cv[3] == 0.0f) {
00036     cv.set(0.0f, 0.0f, 0.0f, w);
00037   } else {
00038     cv *= w / cv[3];
00039   }
00040   return set_cv(n, cv);
00041 }
00042 
00043 ////////////////////////////////////////////////////////////////////
00044 //     Function: NurbsCurveInterface::write_cv
00045 //       Access: Published
00046 //  Description:
00047 ////////////////////////////////////////////////////////////////////
00048 void NurbsCurveInterface::
00049 write_cv(ostream &out, int n) const {
00050   nassertv(n >= 0 && n < get_num_cvs());
00051 
00052   out << "CV " << n << ": " << get_cv_point(n) << ", weight "
00053       << get_cv_weight(n) << "\n";
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: NurbsCurveInterface::write
00058 //       Access: Protected
00059 //  Description:
00060 ////////////////////////////////////////////////////////////////////
00061 void NurbsCurveInterface::
00062 write(ostream &out, int indent_level) const {
00063   indent(out, indent_level);
00064 
00065   float min_t = 0.0f;
00066   float max_t = 0.0f;
00067 
00068   if (get_num_knots() > 0) {
00069     min_t = get_knot(0);
00070     max_t = get_knot(get_num_knots() - 1);
00071   }
00072 
00073   out << "NurbsCurve, order " << get_order() << ", " << get_num_cvs()
00074       << " CV's.  t ranges from " << min_t << " to " << max_t << ".\n";
00075 
00076   indent(out, indent_level)
00077     << "CV's:\n";
00078   int i;
00079   int num_cvs = get_num_cvs();
00080   for (i = 0; i < num_cvs; i++) {
00081     indent(out, indent_level)
00082       << i << ") " << get_cv_point(i) << ", weight "
00083       << get_cv_weight(i) << "\n";
00084   }
00085 
00086   indent(out, indent_level)
00087     << "Knots: ";
00088   int num_knots = get_num_knots();
00089   for (i = 0; i < num_knots; i++) {
00090     out << " " << get_knot(i);
00091   }
00092   out << "\n";
00093 }
00094 
00095 
00096 ////////////////////////////////////////////////////////////////////
00097 //     Function: NurbsCurveInterface::format_egg
00098 //       Access: Protected
00099 //  Description: Formats the Nurbs curve for output to an Egg file.
00100 ////////////////////////////////////////////////////////////////////
00101 bool NurbsCurveInterface::
00102 format_egg(ostream &out, const string &name, const string &curve_type,
00103            int indent_level) const {
00104   indent(out, indent_level)
00105     << "<VertexPool> " << name << ".pool {\n";
00106 
00107   int num_cvs = get_num_cvs();
00108   int cv;
00109   for (cv = 0; cv < get_num_cvs(); cv++) {
00110     indent(out, indent_level+2)
00111       << "<Vertex> " << cv << " { " << get_cv(cv) << " }\n";
00112   }
00113   indent(out, indent_level)
00114     << "}\n";
00115 
00116   indent(out, indent_level)
00117     << "<NurbsCurve> " << name << " {\n";
00118 
00119   if (!curve_type.empty()) {
00120     indent(out, indent_level+2)
00121       << "<Scalar> type { " << curve_type << " }\n";
00122   }
00123 
00124   indent(out, indent_level+2) << "<Order> { " << get_order() << " }\n";
00125 
00126   indent(out, indent_level+2) << "<Knots> {";
00127   int k;
00128   int num_knots = get_num_knots();
00129 
00130   for (k = 0; k < num_knots; k++) {
00131     if (k%6 == 0) {
00132       out << "\n";
00133       indent(out, indent_level+4);
00134     }
00135     out << get_knot(k) << " ";
00136   }
00137   out << "\n";
00138   indent(out, indent_level+2) << "}\n";
00139 
00140   indent(out, indent_level+2) << "<VertexRef> {";
00141   for (cv = 0; cv < num_cvs; cv++) {
00142     if (cv%10 == 0) {
00143       out << "\n";
00144       indent(out, indent_level+3);
00145     }
00146     out << " " << cv;
00147   }
00148   out << "\n";
00149   indent(out, indent_level+4)
00150     << "<Ref> { " << name << ".pool }\n";
00151   indent(out, indent_level+2) << "}\n";
00152 
00153   indent(out, indent_level) << "}\n";
00154 
00155   return true;
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: NurbsCurveInterface::convert_to_nurbs
00160 //       Access: Protected
00161 //  Description: Stores in the indicated NurbsCurve a NURBS
00162 //               representation of an equivalent curve.  Returns true
00163 //               if successful, false otherwise.
00164 ////////////////////////////////////////////////////////////////////
00165 bool NurbsCurveInterface::
00166 convert_to_nurbs(ParametricCurve *nc) const {
00167   NurbsCurveInterface *nurbs = nc->get_nurbs_interface();
00168   nassertr(nurbs != (NurbsCurveInterface *)NULL, false);
00169 
00170   nurbs->remove_all_cvs();
00171   nurbs->set_order(get_order());
00172 
00173   int num_cvs = get_num_cvs();
00174   int i;
00175   for (i = 0; i < num_cvs; i++) {
00176     nurbs->append_cv(get_cv(i));
00177   }
00178 
00179   int num_knots = get_num_knots();
00180   for (i = 0; i < num_knots; i++) {
00181     nurbs->set_knot(i, get_knot(i));
00182   }
00183 
00184   return nc->recompute();
00185 }

Generated on Fri May 2 00:40:46 2003 for Panda by doxygen1.3