File: example12.cpp

package info (click to toggle)
sisl 4.6.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,560 kB
  • sloc: ansic: 84,814; cpp: 4,717; makefile: 7
file content (170 lines) | stat: -rw-r--r-- 6,412 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
 * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
 * Applied Mathematics, Norway.
 *
 * Contact information: E-mail: tor.dokken@sintef.no                      
 * SINTEF ICT, Department of Applied Mathematics,                         
 * P.O. Box 124 Blindern,                                                 
 * 0314 Oslo, Norway.                                                     
 *
 * This file is part of SISL.
 *
 * SISL is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version. 
 *
 * SISL is distributed in the hope that it will be useful,        
 * but WITHOUT ANY WARRANTY; without even the implied warranty of         
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with SISL. If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public
 * License, a covered work must retain the producer line in every data
 * file that is created or manipulated using SISL.
 *
 * Other Usage
 * You can be released from the requirements of the license by purchasing
 * a commercial license. Buying such a license is mandatory as soon as you
 * develop commercial activities involving the SISL library without
 * disclosing the source code of your own applications.
 *
 * This file may be used in accordance with the terms contained in a
 * written agreement between you and SINTEF ICT. 
 */

#include <iostream>
#include <fstream>
#include <string>
#include <stdexcept>
#include <cstdlib>

#include "sisl.h"
#include "GoReadWrite.h"

using namespace std;

namespace {
    string IN_FILE_CURVE = "example4_curve.g2";
    string IN_FILE_SURFACE = "example10_surf.g2";
    string OUT_FILE_POINT   = "example12_isectpoints.g2";

    string DESCRIPTION = 
    //==========================================================
    "This program computes all intersection points between a \n"
    "curve and a surface.  The curve and surface in question has \n"
    "been generated by earlier example programs (example4 and \n"
    "example10), so you should run these first.  The resulting \n"
    "points will be written to the file '" + OUT_FILE_POINT + "'.\n\n";
    //==========================================================

}; // end anonymous namespace 

//===========================================================================
int main(int avnum, char** vararg)
//===========================================================================
{
    cout << '\n' << vararg[0] << ":\n" << DESCRIPTION << endl;
    cout << "To proceed, press enter, or ^C to quit." << endl;
    getchar();

    try {
	ifstream is_cv(IN_FILE_CURVE.c_str());
	ifstream is_sf(IN_FILE_SURFACE.c_str());
	if (!is_cv || !is_sf) {
	    throw runtime_error("Could not open input files.  Have you run "
				"the necessary example programs? (example4 "
				"and example 10).");
	}
	ofstream os(OUT_FILE_POINT.c_str());
	if (!os) {
	    throw runtime_error("Unable to open output file.");
	}

	// reading curve and surface
	SISLCurve* curve = readGoCurve(is_cv);
	SISLSurf* surf = readGoSurface(is_sf);

	// calculating intersection points
	double epsco = 1.0e-15; // computational epsilon
	double epsge = 1.0e-5; // geometric tolerance
	int num_int_points = 0; // number of detected intersection points
	double* intpar_surf  = 0; // parameter values for the surface in the intersections
	double* intpar_curve = 0; // parameter values for the curve in the intersections
	int num_int_curves = 0;   // number of intersection curves
	SISLIntcurve** intcurve = 0; // pointer to array of detected intersection curves
	int jstat; // status variable

	s1858(surf,            // the surface
	      curve,           // the curve
	      epsco,           // computational resolution
	      epsge,           // geometry resolution
	      &num_int_points, // number of single intersection points
	      &intpar_surf,    // pointer to array of parameter values for the surface
	      &intpar_curve,   //               -"-                    for the curve
	      &num_int_curves, // number of detected intersection curves
	      &intcurve,       // pointer to array of detected intersection curves.
	      &jstat);         // status variable
	
	if (jstat < 0) {
	    throw runtime_error("Error occured inside call to SISL routine s1858.");
	} else if (jstat > 0) {
	    cerr << "WARNING: warning occured inside call to SISL routine s1858. \n" 
		     << endl;
	}

	// In this example, we do not expect to find intersection curves, since the 
	// assumed curve does not lie in the surface at any interval with measure > 0.

	cout << "Number of intersection points detected: " << num_int_points << endl;
	cout << "Number of intersection curves detected: " << num_int_curves << endl;
	
	// evaluating intersection points and writing them to file
	vector<double> point_coords_3D(3 * num_int_points);
	int i;
	for (i = 0; i < num_int_points; ++i) {
	    // calculating position, using the curve
	    // (we could also have used the surface, which would give approximately
	    // the same points).
	    int temp;
	    s1227(curve,           // we evaluate on the first curve
		  0,               // calculate no derivatives
		  intpar_curve[i], // parameter value on which to evaluate
		  &temp,           // not used for our purposes (gives parameter interval)
		  &point_coords_3D[3 * i], // result written here
		  &jstat);         // status variable
	    if (jstat < 0) {
		throw runtime_error("Error occured inside call to SISL routine s1227.");
	    } else if (jstat > 0) {
		cerr << "WARNING: warning occured inside call to SISL routine s1227. \n" 
		     << endl;
	    }
	}

	// writing intersection points to file
	writeGoPoints(num_int_points, &point_coords_3D[0], os);

	// cleaning up
	freeSurf(surf);
	freeCurve(curve);
	os.close();
	is_sf.close();
	is_cv.close();
	free(intpar_surf);
	free(intpar_curve);
	for (i = 0; i < num_int_curves; ++i) {
	    freeIntcurve(intcurve[i]);
	}
	free(intcurve);

    } catch (exception& e) {
	cerr << "Exception thrown: " << e.what() << endl;
	return 0;
    }

    return 1;
};