Hi,
I am quite new to the openNURBS and need some help with writing multiple cylinders or boxes to a 3DM file. I modified the example_brep.cpp file to write two cylinders but I see only the first cylinder in the resulting 3dm file. The final goal is to be able to read multiple cylinders of varying sizes and orientation and write them into a single 3dm file.
Thanks,
Vimal
#include "../opennurbs.h"
#include "../examples_linking_pragmas.h"
#include <map>
#include <string>
using namespace std;
static ON_Brep* MakeCylinder(const double Diameter,
const double Length,
const ON_3dPoint Origin,
const ON_3dVector Axis,
ON_TextLog& error_log )
{
double Radius;
// Radius of Cylinder
Radius = 0.5*Diameter;
// Base Plane on which the cylinder is drawn
ON_Plane base(Origin,Axis);
// Base Circle
ON_Circle base_circle(base,Radius);
// Base Cylinder
ON_Cylinder cylinder(base_circle,Length);
//Brep
ON_Brep *brep = ON_BrepCylinder( cylinder, TRUE, TRUE );
return brep;
}
//int main( int argc, const char *argv[] )
int main()
{
// Mapping of Cylinder Axis
std::map<std::string, ON_3dVector> Axis;
Axis["-X"] = ON_3dVector(-1.0, 0.0, 0.0);
Axis["X"] = ON_3dVector(+1.0, 0.0, 0.0);
Axis["-Y"] = ON_3dVector( 0.0,-1.0, 0.0);
Axis["Y"] = ON_3dVector( 0.0,+1.0, 0.0);
Axis["-Z"] = ON_3dVector( 0.0, 0.0,-1.0);
Axis["Z"] = ON_3dVector( 0.0, 0.0,+1.0);
// Initialze opennurbs library
ON::Begin();
// Error Log
ON_TextLog error_log;
// 3DM Model
ONX_Model model;
// Add Cylinder
ONX_Model_Object& mo = model.m_object_table.AppendNew();
ON_Brep* brep = new ON_Brep();
{
brep = MakeCylinder(5.0,40.0,ON_3dPoint(10.0,10.0,-20.0),Axis["-Z"],error_log);
if (!brep) return 1;
mo.m_object = brep;
mo.m_bDeleteObject = true; // ~ONX_Model will delete brep
brep = 0;
}
brep = MakeCylinder(8.0,10.0,ON_3dPoint(50.0,20.0,-20.0),Axis["-X"],error_log);
if (!brep) return 1;
mo.m_object = brep;
mo.m_bDeleteObject = true; // ~ONX_Model will delete brep
brep = 0;
// version will be ON_BinaryArchive::CurrentArchiveVersion()
int version = 0;
// Output Model
model.Polish();
const char* filename = "my_brep.3dm";
bool rc = model.Write(filename,
version,
__FILE__ "example_brep.cpp " __DATE__,
&error_log
);
if (rc)
printf("Wrote %s.\n",filename);
else
printf("Errors writing %s.\n",filename);
// Clean up opennurbs class definition information.
// Opennurbs will not work correctly after ON::End() is called.
ON::End();
return 0;
}