1 /*
2  * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
3  * Applied Mathematics, Norway.
4  *
5  * Contact information: E-mail: tor.dokken@sintef.no
6  * SINTEF ICT, Department of Applied Mathematics,
7  * P.O. Box 124 Blindern,
8  * 0314 Oslo, Norway.
9  *
10  * This file is part of SISL.
11  *
12  * SISL is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Affero General Public License as
14  * published by the Free Software Foundation, either version 3 of the
15  * License, or (at your option) any later version.
16  *
17  * SISL is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Affero General Public License for more details.
21  *
22  * You should have received a copy of the GNU Affero General Public
23  * License along with SISL. If not, see
24  * <http://www.gnu.org/licenses/>.
25  *
26  * In accordance with Section 7(b) of the GNU Affero General Public
27  * License, a covered work must retain the producer line in every data
28  * file that is created or manipulated using SISL.
29  *
30  * Other Usage
31  * You can be released from the requirements of the license by purchasing
32  * a commercial license. Buying such a license is mandatory as soon as you
33  * develop commercial activities involving the SISL library without
34  * disclosing the source code of your own applications.
35  *
36  * This file may be used in accordance with the terms contained in a
37  * written agreement between you and SINTEF ICT.
38  */
39 
40 #include <iostream>
41 #include <fstream>
42 #include <string>
43 #include <stdexcept>
44 #include <cstdlib>
45 
46 #include "sisl.h"
47 #include "GoReadWrite.h"
48 
49 using namespace std;
50 
51 
52 namespace {
53     string OUT_FILE_POINTS = "example2_points.g2";
54     string OUT_FILE_CURVE  = "example2_curve.g2";
55 
56     string DESCRIPTION =
57     "This program will generate a SISL spline curve object by \n"
58     "interpolating a set of given points.  The parametrization \n"
59     "will be calculated automatically.  No derivative \n"
60     "information is provided.  The routine used is 's1356'. The \n"
61     "points will be written in Go-format to the file: \n'"
62     + OUT_FILE_POINTS + "'.  The resulting curve will be written \n"
63     "in Go-format to the file: '" + OUT_FILE_CURVE + "'\n";
64 
65     const int num_points = 6;
66     const double cstartpar = 0;
67 
68     int type[] = {1, 1, 1, 1, 1, 1};
69 
70     double points[] = {0, 0, 0,
71 		       1, 1, 0,
72 		       2, -1, 0,
73 		       3, 0, 0,
74 		       4, 1, 1,
75 		       3, 0, 4};
76 }; // end anonymous namespace
77 
78 //===========================================================================
main(int avnum,char ** vararg)79 int main(int avnum, char** vararg)
80 //===========================================================================
81 {
82     cout << '\n' << vararg[0] << ":\n" << DESCRIPTION << endl;
83     cout << "To proceed, press enter, or ^C to quit." << endl;
84     getchar();
85 
86 
87     try {
88 
89 	double cendpar;
90 	SISLCurve* result_curve = 0;
91 	double* gpar = 0;
92 	int jnbpar;
93 	int jstat;
94 
95 	s1356(points,        // pointer to where the point coordinates are stored
96 	      num_points,    // number of points to be interpolated
97 	      3,             // the dimension
98 	      type,          // what type of information is stored at a particular point
99 	      0,             // no additional condition at start point
100 	      0,             // no additional condition at end point
101 	      1,             // open curve
102 	      4,             // order of the spline curve to be produced
103 	      cstartpar,     // parameter value to be used at start of curve
104 	      &cendpar,      // parameter value at the end of the curve (to be determined)
105 	      &result_curve, // the resulting spline curve (to be determined)
106 	      &gpar,         // pointer to the parameter values of the points in the curve
107 	                     // (to be determined)
108 	      &jnbpar,       // number of unique parameter values (to be determined)
109 	      &jstat);       // status message
110 
111 	if (jstat < 0) {
112 	    throw runtime_error("Error occured inside call to SISL routine.");
113 	} else if (jstat > 0) {
114 	    cerr << "WARNING: warning occured inside call to SISL routine. \n" << endl;
115 	}
116 
117 	cout << "Total parameter interval of curve: [" << cstartpar << ", "
118 	     << cendpar << "]\n\n";
119 	cout << "Point parameter values was decided to be: \n";
120 	for (int i = 0; i < num_points; ++i) {
121 	    cout << gpar[i] << ' ';
122 	}
123 	cout << endl;
124 
125 	ofstream os_points(OUT_FILE_POINTS.c_str());
126 	ofstream os_curve(OUT_FILE_CURVE.c_str());
127 	if (!os_points || !os_curve) {
128 	    throw runtime_error("Unable to open output file.");
129 	}
130 
131 	// write result to file
132 	writeGoPoints(num_points, points, os_points);
133 	writeGoCurve(result_curve, os_curve);
134 
135 	// cleaning up
136 	freeCurve(result_curve);
137 	free(gpar);
138 	os_points.close();
139 	os_curve.close();
140 
141     } catch (exception& e) {
142 	cerr << "Exception thrown: " << e.what() << endl;
143 	return 0;
144     }
145 
146     return 1;
147 };
148