Biomechanical Joint Model
 Author: Anderson Maciel

nbody.cpp

Go to the documentation of this file.
00001 /************************************************************************\
00002 
00003   Copyright 1997 The University of North Carolina at Chapel Hill.
00004   All Rights Reserved.
00005 
00006   Permission to use, copy, modify and distribute this software
00007   and its documentation for educational, research and non-profit
00008   purposes, without fee, and without a written agreement is
00009   hereby granted, provided that the above copyright notice and
00010   the following three paragraphs appear in all copies.
00011 
00012   IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL
00013   HILL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
00014   INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
00015   ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
00016   EVEN IF THE UNIVERSITY OF NORTH CAROLINA HAVE BEEN ADVISED OF
00017   THE POSSIBILITY OF SUCH DAMAGES.
00018 
00019 
00020   Permission to use, copy, modify and distribute this software
00021   and its documentation for educational, research and non-profit
00022   purposes, without fee, and without a written agreement is
00023   hereby granted, provided that the above copyright notice and
00024   the following three paragraphs appear in all copies.
00025 
00026   THE UNIVERSITY OF NORTH CAROLINA SPECIFICALLY DISCLAIM ANY
00027   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00028   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029   PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
00030   BASIS, AND THE UNIVERSITY OF NORTH CAROLINA HAS NO OBLIGATION
00031   TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
00032   MODIFICATIONS.
00033 
00034 
00035    --------------------------------- 
00036   |Please send all BUG REPORTS to:  |
00037   |                                 |
00038   |   geom@cs.unc.edu               |
00039   |                                 |
00040    ---------------------------------
00041   
00042      
00043   The authors may be contacted via:
00044 
00045   US Mail:  A. Pattekar/J. Cohen/T. Hudson/S. Gottschalk/M. Lin/D. Manocha
00046             Department of Computer Science
00047             Sitterson Hall, CB #3175
00048             University of N. Carolina
00049             Chapel Hill, NC 27599-3175
00050             
00051   Phone:    (919)962-1749
00052             
00053   EMail:    geom@cs.unc.edu
00054 
00055 \************************************************************************/
00056 #include <iostream.h>
00057 #include <stdio.h>
00058 #include <stdlib.h>
00059 #include "VCollide.H"
00060 
00061 const int NO_OF_OBJECTS=20;      //number of instances
00062 const int SIMULATION_STEPS=100;  //number of steps in the simulation.
00063 
00064 main(int argc, char *argv[])
00065 {
00066 
00067   if (argc != 3)
00068     {
00069       cerr<<argv[0]<<": USAGE: "<<argv[0]<<" <input-file> <transformation-file>\n";
00070       exit(1);
00071     }
00072   
00073   int num_tri;
00074   VCollide vc;
00075   int id[NO_OF_OBJECTS];
00076   
00077   int i;
00078   for (i=0; i<NO_OF_OBJECTS; i++)  //add the objects to the library.
00079     {
00080       cout<<"Reading object "<<i<<"\n";
00081       vc.NewObject(&(id[i]));
00082       cout<<"Adding triangles\n";
00083       FILE *fp = fopen(argv[1], "r");
00084       fscanf(fp, "%d", &num_tri);
00085       
00086       for (int j=1; j<=num_tri; j++)
00087         {
00088           double v1[3], v2[3], v3[3];
00089           fscanf(fp, "%lf %lf %lf", &(v1[0]), &(v1[1]), &(v1[2]));
00090           fscanf(fp, "%lf %lf %lf", &(v2[0]), &(v2[1]), &(v2[2]));
00091           fscanf(fp, "%lf %lf %lf", &(v3[0]), &(v3[1]), &(v3[2]));
00092           
00093           vc.AddTri(v1, v2, v3);
00094         }
00095       
00096       fclose(fp);
00097       
00098       cout<<"Calling finish_object\n";
00099       vc.EndObject();
00100       
00101       
00102       cout<<"Inserted object "<<i<<"\n";
00103     }
00104   
00105   
00106   FILE *fp = fopen(argv[2], "r");
00107   
00108   for (i=1; i<=SIMULATION_STEPS; i++)  //perform the simulation.
00109     {
00110       cout<<"Simulation step : "<<i<<"\n";
00111       int j;
00112       for (j=0; j<NO_OF_OBJECTS; j++)
00113         {
00114           double trans[4][4];
00115           
00116           //read in the transformation matrix.
00117           fscanf(fp, "%lf", &(trans[0][0]));
00118           fscanf(fp, "%lf", &(trans[0][1]));
00119           fscanf(fp, "%lf", &(trans[0][2]));
00120           fscanf(fp, "%lf", &(trans[0][3]));
00121           
00122           fscanf(fp, "%lf", &(trans[1][0]));
00123           fscanf(fp, "%lf", &(trans[1][1]));
00124           fscanf(fp, "%lf", &(trans[1][2]));
00125           fscanf(fp, "%lf", &(trans[1][3]));
00126           
00127           fscanf(fp, "%lf", &(trans[2][0]));
00128           fscanf(fp, "%lf", &(trans[2][1]));
00129           fscanf(fp, "%lf", &(trans[2][2]));
00130           fscanf(fp, "%lf", &(trans[2][3]));
00131           
00132           fscanf(fp, "%lf", &(trans[3][0]));
00133           fscanf(fp, "%lf", &(trans[3][1]));
00134           fscanf(fp, "%lf", &(trans[3][2]));
00135           fscanf(fp, "%lf", &(trans[3][3]));
00136           
00137           //update the object's transformation.
00138           vc.UpdateTrans(id[j], trans);
00139         }
00140       
00141       vc.Collide();  //perform collision test.
00142       
00143       //report the results.
00144       int VCReportSize=10;
00145       VCReportType *vcrep = new VCReportType[VCReportSize];
00146       
00147       int no_of_colliding_pairs = vc.Report(VCReportSize, vcrep);
00148       
00149       if (no_of_colliding_pairs > VCReportSize)
00150         {
00151           VCReportSize=no_of_colliding_pairs;
00152           delete vcrep;
00153           vcrep = new VCReportType[VCReportSize];
00154           no_of_colliding_pairs = vc.Report(VCReportSize, vcrep);
00155         }
00156       
00157       for (j=0; j<no_of_colliding_pairs; j++)
00158         cout<<"Detected collision between objects "<<vcrep[j].id1<<" and "<<vcrep[j].id2<<"\n";
00159       
00160     }
00161 }

Generated on Thu Dec 1 10:13:39 2005 for COME - Biomechanical Joint Model by  doxygen 1.4.5