26#include <onurbs/opennurbs.h>
38void writeON_Init(ONX_Model & model)
46 model.m_properties.m_RevisionHistory.NewRevision();
49 model.m_properties.m_Application.m_application_name =
"OpenNURBS write_curves_example() function";
50 model.m_properties.m_Application.m_application_URL =
"http://www.opennurbs.org";
51 model.m_properties.m_Application.m_application_details =
"Example program in OpenNURBS toolkit.";
54 model.m_properties.m_Notes.m_notes =
"This file was made with the OpenNURBS write_curves_example() function.";
55 model.m_properties.m_Notes.m_bVisible =
true;
59 model.m_settings.m_ModelUnitsAndTolerances.m_unit_system = ON::inches;
60 model.m_settings.m_ModelUnitsAndTolerances.m_absolute_tolerance = 0.001;
61 model.m_settings.m_ModelUnitsAndTolerances.m_angle_tolerance = ON_PI/180.0;
62 model.m_settings.m_ModelUnitsAndTolerances.m_relative_tolerance = 0.01;
74bool writeON_Write3dm(ONX_Model & model,
const std::string & fname)
76 const char* filename = fname.c_str();
82 ON_TextLog message_log;
100 FILE* fp = ON::OpenFile( filename,
"wb" );
101 ON_BinaryFile archive( ON::write3dm, fp );
103 const char* sStartSectionComment = __FILE__
"write_points_example()" __DATE__;
107 bool ok = model.Write(archive, version, sStartSectionComment, &error_log );
111 message_log.Print(
"Successfully wrote %s.\n",filename);
113 message_log.Print(
"Errors while writing %s.\n",filename);
126 ON_NurbsCurve* wiggle =
new ON_NurbsCurve(
133 for (
int k = 0; k < wiggle->CVCount(); k++ )
135 ON_3dPoint pt( cast<T,double>(curve.
coef(k,0)), cast<T,double>(curve.
coef(k,1)), 0.0 );
136 wiggle->SetCV( k, pt );
143 for (
size_t k = 1; k < kv.size()-1; k++ )
145 wiggle->SetKnot(k-1, cast<T,double>(kv[k]) );
149 if ( wiggle->IsValid(&log) )
151 ONX_Model_Object& mo = model.m_object_table.AppendNew();
152 mo.m_object = wiggle;
153 mo.m_bDeleteObject =
true;
154 mo.m_attributes.m_layer_index = 0;
155 mo.m_attributes.m_name = name.c_str();
167 ONX_Model & model,
const std::string & name)
169 ON_NurbsSurface* onsurf =
new ON_NurbsSurface(
172 surface.
basis().degree(0)+1,
173 surface.
basis().degree(1)+1,
174 surface.
basis().component(0).size(),
175 surface.
basis().component(1).size()
179 bool fs = (surface.
geoDim()<3?
false:
true);
180 for (
int j = 0; j < onsurf->CVCount(1); j++ )
181 for (
int i = 0; i < onsurf->CVCount(0); i++ )
183 ON_3dPoint pt(cast<T,double>(surface.
coef(c,0)), cast<T,double>(surface.
coef(c,1)), (fs? cast<T,double>(surface.
coef(c,2)) : 0.0) );
185 onsurf->SetCV( i, j, pt );
194 for (
size_t k = 1; k < kv1.
size()-1; k++ )
195 onsurf->SetKnot(0, k-1, cast<T,double>(kv1[k]) );
197 for (
size_t k = 1; k < kv2.
size()-1; k++ )
198 onsurf->SetKnot(1, k-1, cast<T,double>(kv2[k]) );
201 if ( onsurf->IsValid(&log) )
203 ONX_Model_Object& mo = model.m_object_table.AppendNew();
204 mo.m_object = onsurf;
205 mo.m_bDeleteObject =
true;
206 mo.m_attributes.m_layer_index = 0;
207 mo.m_attributes.m_name = name.c_str();
217bool writeON_NurbsSurface(
const gsSurface<T> & srf,
const std::string & name)
221 writeON_NurbsSurface(srf, model,
"srf");
222 return writeON_Write3dm(model,name+
".3dm");
226bool writeON_NurbsCurve(
const gsCurve<T> & curve,
const std::string & name)
230 writeON_NurbsCurve(curve, model,
"curve");
231 return writeON_Write3dm(model,name+
".3dm");
241 for(
size_t i = 0; i < patches.
nPatches(); ++i)
244 std::stringstream nm(
"patch");
258 return writeON_Write3dm(model,name+
".3dm");
268 for(
index_t i =0; i<pd.numLoops();i++)
269 for(
index_t j =0; j< pd.loop(i).numCurves() ; j++)
272 gsInfo<<
"Write loop "<< i <<
", curve "<<j<<
"\n";
274 std::stringstream nm(
"curve");
280 return writeON_Write3dm(model,name+
".3dm");
291 const size_t nf = msh.numFaces();
292 const size_t nv = msh.numVertices();
294 ON_Mesh* mesh =
new ON_Mesh(nf, nv,
true,
false);
296 for (
size_t i = 0; i < nv; i++)
299 mesh->SetVertex(i, ON_3fPoint(cast<T,double>(v.x()), cast<T,double>(v.y()), cast<T,double>(v.z())) );
303 for (
size_t i = 0; i < nf; i++)
305 v = msh.faceIndices(i);
309 mesh->SetTriangle(i, v[0], v[1], v[2]);
312 mesh->SetQuad(i, v[0], v[1], v[2], v[3]);
319 mesh->ComputeVertexNormals();
323 if ( mesh->IsValid(&log) )
325 ONX_Model_Object& mo = model.m_object_table.AppendNew();
327 mo.m_bDeleteObject =
true;
328 mo.m_attributes.m_layer_index = 0;
329 mo.m_attributes.m_name = name.c_str();
335 return writeON_Write3dm(model,name+
".3dm");
A univariate B-spline basis.
Definition gsBSplineBasis.h:700
Abstract base class representing a curve.
Definition gsCurve.h:31
gsMatrix< T >::RowXpr coef(index_t i)
Returns the i-th coefficient of the geometry as a row expression.
Definition gsGeometry.h:346
short_t geoDim() const
Dimension n of the absent physical space.
Definition gsGeometry.h:292
virtual const gsBasis< T > & basis() const =0
Returns a const reference to the basis of the geometry.
index_t coefsSize() const
Return the number of coefficients (control points)
Definition gsGeometry.h:371
Class for representing a knot vector.
Definition gsKnotVector.h:80
size_t size() const
Number of knots (including repetitions).
Definition gsKnotVector.h:242
Class Representing a triangle mesh with 3D vertices.
Definition gsMesh.h:32
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition gsMultiPatch.h:100
gsGeometry< T > & patch(size_t i) const
Return the i-th patch.
Definition gsMultiPatch.h:292
size_t nPatches() const
Number of patches.
Definition gsMultiPatch.h:274
Class representing a Planar domain with an outer boundary and a number of holes.
Definition gsPlanarDomain.h:44
Abstract base class representing a surface.
Definition gsSurface.h:31
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
gsVertex class that represents a 3D vertex for a gsMesh.
Definition gsVertex.h:27
Provides declaration of BSplineBasis class.
#define index_t
Definition gsConfig.h:32
#define gsInfo
Definition gsDebug.h:43
Knot vector for B-splines.
Provides declaration of the Mesh class.
Provides declaration of the MultiPatch class.
Provides declaration of gsPlanarDomain class. The outer boundary (m_loops[0]) is a loop of curves,...
Provides declaration of functions that write 3DM file format.
bool writeON_PlanarDomain(const gsPlanarDomain< T > &pd, const std::string &name)
Writes a planar domain to OpenNurbs file.
Definition gsWriteOpenNurbs.hpp:263
bool writeON_NurbsSurface(const gsSurface< T > &curve, ONX_Model &model, const std::string &name)
Writes a Surface to OpenNurbs file.
Definition gsWriteOpenNurbs.hpp:166
bool writeON_NurbsCurve(const gsCurve< T > &curve, ONX_Model &model, const std::string &name)
Writes a Curve to OpenNurbs file.
Definition gsWriteOpenNurbs.hpp:123
bool writeON_MultiPatch(const gsMultiPatch< T > &patches, const std::string &name)
Writes a MultiPatch to OpenNurbs file.
Definition gsWriteOpenNurbs.hpp:236
bool writeON_Mesh(const gsMesh< T > &msh, const std::string &name)
Writes a Mesh to OpenNurbs file.
Definition gsWriteOpenNurbs.hpp:286
The G+Smo namespace, containing all definitions for the library.