Developer Documentation
Loading...
Searching...
No Matches
BSplineWriters.cc
1/*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40\*===========================================================================*/
41
42
43
44#include "FileOBJ.hh"
45
46
47#ifdef ENABLE_BSPLINECURVE_SUPPORT
48bool FileOBJPlugin::writeCurve(std::ostream& _out, QString _filename, BSplineCurve* _curve )
49{
50 if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0) {
51 _out.precision(savePrecision_->value());
52 }
53
54 _out << "# " << _filename.toStdString() << "\n";
55
56 // save control points (coordinates)
57 for (uint i = 0; i < _curve->n_control_points(); ++i){
58 ACG::Vec3d cp = _curve->get_control_point(i);
59 _out << "v " << cp[0] << " " << cp[1] << " " << cp[2] << "\n";
60 }
61
62 _out << "cstype bspline\n";
63 _out << "deg " << _curve->degree() << "\n";
64 _out << "g " << _filename.toStdString() << "\n";
65
66 // save control polygon
67 _out << "curv " << _curve->get_knot(0) << " " << _curve->get_knot(_curve->n_knots()-1) << " ";
68 // save control point indices
69 for (unsigned int i = 0; i < _curve->n_control_points(); ++i)
70 _out << i+1 << " "; // obj enumerates the cps starting with 1
71 _out << "\n";
72
73 _out << "parm u ";
74 // save knotvector
75 for (unsigned int i = 0; i < _curve->n_knots(); ++i)
76 _out << _curve->get_knot(i) << " ";
77 _out << "\n";
78
79 _out << "end";
80
81 return true;
82}
83#endif
84
85#ifdef ENABLE_BSPLINESURFACE_SUPPORT
86bool FileOBJPlugin::writeSurface(std::ostream& _out, QString _filename, BSplineSurface* _surface ){
87 if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0) {
88 _out.precision(savePrecision_->value());
89 }
90
91 _out << "# " << _filename.toStdString() << "\n";
92
93 // save control net (coordinates)
94 unsigned int num_cp_m = _surface->n_control_points_m();
95 unsigned int num_cp_n = _surface->n_control_points_n();
96
97 for (unsigned int i = 0; i < num_cp_m; ++i)
98 {
99 for (unsigned int j = 0; j < num_cp_n; ++j)
100 {
101 ACG::Vec3d cp = (*_surface)(i,j);
102 _out << "v " << cp[0] << " " << cp[1] << " " << cp[2] << "\n";
103 }
104 }
105
106 _out << "cstype bspline\n";
107 _out << "deg " << _surface->degree_m() << " " << _surface->degree_n() << "\n";
108 _out << "g " << _filename.toStdString() << "\n";
109
110 // save control polygon
111 _out << "surf " << _surface->get_knot_m(0) << " " << _surface->get_knot_m(_surface->n_knots_m()-1) << " "
112 << _surface->get_knot_n(0) << " " << _surface->get_knot_n(_surface->n_knots_n()-1) << " ";
113
114 // save control point indices
115 for (unsigned int j = 0; j < num_cp_n; ++j)
116 for (unsigned int i = 0; i < num_cp_m; ++i)
117 _out << (i*num_cp_n) + j+1 << " "; // obj enumerates the cps starting with 1
118
119 _out << "\n";
120
121 _out << "parm u ";
122 // save knotvector in m direction
123 for (unsigned int i = 0; i < _surface->n_knots_m(); ++i)
124 _out << _surface->get_knot_m(i) << " ";
125 _out << "\n";
126
127 _out << "parm v ";
128 // save knotvector in n direction
129 for (unsigned int i = 0; i < _surface->n_knots_n(); ++i)
130 _out << _surface->get_knot_n(i) << " ";
131 _out << "\n";
132
133 _out << "end";
134
135 return true;
136}
137
138#endif
139
unsigned int n_control_points() const
Returns the number of control points.
Point & get_control_point(int _i)
get control point i
Scalar get_knot(int _i)
get knot i
unsigned int n_knots() const
Returns the number of knots.
unsigned int degree() const
Returns the spline degree.
unsigned int n_control_points_n() const
Returns the number of controlpoints in n direction.
unsigned int n_knots_m()
Returns the number of knots in m direction.
unsigned int n_knots_n()
Returns the number of knots in n direction.
Scalar get_knot_m(int _i)
Get knot i in m direction.
int degree_n() const
Returns the spline degree in n direction.
Scalar get_knot_n(int _i)
Get knot i in n direction.
unsigned int n_control_points_m() const
Returns the number of controlpoints in m direction.
int degree_m() const
Returns the spline degree in m direction.