LR-splines  0.5
BezierExtract.cpp
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <iostream>
00003 #include <string.h>
00004 #include <fstream>
00005 #include "LRSpline/LRSplineVolume.h"
00006 #include "LRSpline/Profiler.h"
00007 #include "LRSpline/Element.h"
00008 #include "LRSpline/Meshline.h"
00009 
00010 using namespace LR;
00011 using namespace std;
00012 
00013 int main(int argc, char **argv) {
00014         int el = -1;
00015         string filename = "";
00016 
00017         // read input parameters
00018         for(int i=1; i<argc; i++) {
00019                 if(strcmp(argv[i],"-el") == 0) {
00020                         el = atoi(argv[++i]);
00021                 } else if(filename.length() > 0) {
00022                         cout << "Usage: " << argv[0] << " [-el <n>] <inputfile>\n";
00023                         exit(1);
00024                 } else  {
00025                         filename = argv[i];
00026                 }
00027         }
00028         
00029         if(filename.length() == 0) {
00030                 cout << "Usage: " << argv[0] << " [-el <n>] <inputfile>\n";
00031                 exit(1);
00032         }
00033         
00034         // read lr file
00035         ifstream inputfile;
00036         inputfile.open(filename.c_str());
00037         if(!inputfile.is_open()) {
00038                 cerr << "Error: could not open file " << filename << endl;
00039                 exit(2);
00040         }
00041         LRSplineVolume lr;
00042         inputfile >> lr;
00043 
00044         if(lr.dimension() != 3) {
00045                 cerr << "Nag on lazy Kjetil to make this test for dimensions other than 3 as well\n";
00046                 exit(3);
00047         }
00048 
00049         int comp = 1;
00050         for(int i=0; i<3; i++)
00051                 comp *= lr.order(i);
00052         
00053         vector<double> cp;
00054         if(el < 0) {
00055                 for(int i=0; i<lr.nElements(); i++) {
00056                         printf("Element #%3d\n", i);
00057                         lr.getBezierElement(i, cp);
00058                         int ip=0;
00059                         for(int j=0; j<comp; j++, ip+=3)
00060                                 printf("  (%.3f, %.3f, %.3f)\n", cp[ip], cp[ip+1], cp[ip+2]);
00061                 }
00062         } else {
00063                 lr.getBezierElement(el, cp);
00064                 printf("Element #%3d\n", el);
00065                 int ip=0;
00066                 for(int j=0; j<comp; j++, ip+=3)
00067                         printf("  (%.3f, %.3f, %.3f)\n", cp[ip], cp[ip+1], cp[ip+2]);
00068         }
00069 
00070 }