BRL-CAD
nurb_brep.cpp
Go to the documentation of this file.
1 /* N U R B _ B R E P . C P P
2  * BRL-CAD
3  *
4  * Copyright (c) 2009-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file nurb_poly.c
21  *
22  * Convert old NURBS to new NURBS
23  *
24  */
25 
26 #include "common.h"
27 
28 #include "raytrace.h"
29 #include "rtgeom.h"
30 #include "nurb.h"
31 #include "brep.h"
32 
33 
34 extern "C" void
35 rt_nurb_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol *)
36 {
37  int i, j, k;
38  struct rt_nurb_internal *nip;
39 
41  nip = (struct rt_nurb_internal *)ip->idb_ptr;
42  RT_NURB_CK_MAGIC(nip);
43 
44  ON_TextLog log(stderr);
45 
46  for (i = 0; i < nip->nsrf; i++) {
47  struct face_g_snurb *surface = nip->srfs[i];
48  NMG_CK_SNURB(surface);
49 
50  ON_NurbsSurface *nurb = ON_NurbsSurface::New(3, true, surface->order[0], surface->order[1], surface->s_size[0], surface->s_size[1]);
51 
52  /* set 'u' knots */
53  /* skip first and last (duplicates?) */
54  for (j = 1; j < surface->u.k_size - 1; j++) {
55  nurb->SetKnot(0, j-1, surface->u.knots[j]);
56  /* bu_log("u knot %d is %f\n", j-1, surface->u.knots[j]); */
57  }
58  /* set 'v' knots */
59  /* skip first and last (duplicates?) */
60  for (j = 1; j < surface->v.k_size - 1; j++) {
61  nurb->SetKnot(1, j-1, surface->v.knots[j]);
62  /* bu_log("v knot %d is %f\n", j-1, surface->u.knots[j]); */
63  }
64 
65  /* set control points */
66  for (j = 0; j < surface->s_size[0]; j++) {
67  for (k = 0; k < surface->s_size[1]; k++) {
68  ON_3dPoint point = &RT_NURB_GET_CONTROL_POINT(surface, j, k);
69  nurb->SetCV(k, j, point);
70  }
71  }
72 
73  /* nurb->Dump(log); */
74  bu_log("NURBS surface %d %s valid\n", i, nurb->IsValid(&log) ? "is" : "is not");
75 
76  (*b)->m_S.Append(nurb);
77  int sindex = (*b)->m_S.Count();
78  (*b)->NewFace(sindex - 1);
79  int findex = (*b)->m_F.Count();
80  (*b)->NewOuterLoop(findex - 1);
81  }
82 
83  bu_log("BREP object %s a single surface\n", (*b)->IsSurface() ? "is" : "is not");
84  bu_log("BREP object %s valid\n", (*b)->IsValid(&log) ? "is" : "is not");
85  bu_log("BREP object %s valid topology\n", (*b)->IsValidTopology(&log) ? "is" : "is not");
86  bu_log("BREP object %s valid geometry\n", (*b)->IsValidGeometry(&log) ? "is" : "is not");
87  bu_log("BREP object %s solid\n", (*b)->IsSolid() ? "is" : "is not");
88  bu_log("BREP object %s manifold\n", (*b)->IsManifold() ? "is" : "is not");
89 }
90 
91 
92 /*
93  * Local Variables:
94  * mode: C
95  * tab-width: 8
96  * indent-tabs-mode: t
97  * c-file-style: "stroustrup"
98  * End:
99  * ex: shiftwidth=4 tabstop=8
100  */
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
Header file for the BRL-CAD common definitions.
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
Coord * point
Definition: chull3d.cpp:52
Support for uniform tolerances.
Definition: tol.h:71
void * idb_ptr
Definition: raytrace.h:195
void rt_nurb_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol *)
Definition: nurb_brep.cpp:35