John,
Thanks very much for the assistance! I'm composing this on a train on my
elderly notbook, but will be back with my box soon, so will try the
programs with the strcmp() thing when I get back. In the mean time, I've
included the code of my program so far....
#include "stdafx.h"
#include "stdlib.h"
#include "math.h"
#include "iostream.h"
#include "iomanip.h"
#include "fstream.h"
#include "vectorr1_1.h"
#include "string.h"
#include "string"
// I'm sure I don't need all these, but I'll strip them out later.
int main()
{
char fileName[255];
cout << "Enter the name of the input *.STL file (including extension): ";
cin >> fileName;
ifstream inf(fileName);
char buffer[128];
char * ehWhy;
int facetTot=1;
int facetNum=0;
int normFlag=0;
int vertFlag=0;
int compFlag=0;
int solidFlag=0;
char vcheck[128] = "\nvertex";
char ncheck[128] = "\nnormal";
while(!inf.getline(buffer, 128 ,' ').eof())
{
// What I have done here is put the carriage return from
// the line before in the buffer check. Do I need to do this?
// If so is this the right way? or should I use that ignore
// doodad that I have seen in reference to strings
if(buffer == "\nfacet")
{
facetTot++;
}
}
const int facetTot1 = facetTot;
// This was 'line 54' - I've stripped some stuff to uncomplicate it.
// The compiler doesn't like it. Even with facetTot set to 1 (I'll
// fix the exact facet numbering later).
vector mySurface[facetTot1][4];
while(!inf.getline(buffer, 128, ' ').eof())
{
if (buffer == "\nnormal")
{
cout << ".";
normFlag=1;
compFlag=1;
} else if (buffer == "\nvertex" )
{
vertFlag++;
} else if (normFlag != 0)
{
// This is one thing I don't understand. TBH I'm not really sure
// about pointers in general, but am particularly curious as to
// why this pointer is necessary.
mySurface[facetNum][4].setComp(compFlag, strtod(buffer,&ehWhy));
compFlag++;
if (compFlag == 4)
{
compFlag=0;
normFlag=0;
}
} else if (vertFlag != 0)
{
mySurface[facetNum][vertFlag].setComp(compFlag, strtod(buffer,&ehWhy));
compFlag++;
if (compFlag == 4)
{
compFlag=0;
if (vertFlag == 4)
{
vertFlag=0;
facetNum++;
}
}
}
}
return 0;
}
******* End of main code file. ***********
******* Begin Vector.h *********
#include "iostream.h"
#include "math.h"
class vector
{
protected: // The 'protected' part ensures that 'xcoord' etc. are only
accessible from withing this specific class.
double xcoord, ycoord, zcoord;
public:
// Default constructor: when a vector is specified without arguments, it's
default co-cordinates are set to '0'
vector()
{
xcoord=0;
ycoord=0;
zcoord=0;
}
// Cartesian constructor: when argumants are supplied, they are set as the
co-ordinates.
vector(double x, double y, double z)
{
xcoord=x;
ycoord=y;
zcoord=z;
}
// Prints out to the screen.
void print()
{
cout << "(" << xcoord << "," << ycoord << "," << zcoord << ")";
}
// Access methods for the co-ordinates
double getx()
{
return xcoord;
}
double gety()
{
return ycoord;
}
double getz()
{
return zcoord;
}
double getComp(int compNum)
{
if (compNum == 1)
{
return xcoord;
} else if (compNum == 2)
{
return ycoord;
} else if (compNum == 3)
{
return zcoord;
} else
{
cout << "\n\n Error! Error! Vector getComp\n\n";
}
}
double lenOf()
{
double lengthVal=0;
lengthVal=(xcoord*xcoord);
lengthVal+=(ycoord*ycoord);
lengthVal+=(zcoord*zcoord);
return lengthVal;
}
void setx( double value)
{
xcoord=value;
}
void sety( double value)
{
ycoord=value;
}
void setz( double value)
{
zcoord=value;
}
void setComp(int compNum, double value)
{
if (compNum == 1)
{
xcoord=value;
} else if (compNum == 2)
{
ycoord=value;
} else if (compNum == 3)
{
zcoord=value;
} else
{
cout << "\n\n Error! Error! Vector setComp\n\n";
}
}
// Overload + - Addition
vector operator+(vector v_old)
{
vector v_sum(v_old.getx()+xcoord, v_old.gety()+ycoord, v_old.getz()
+zcoord);
return v_sum;
}
// Overload - - Subtraction
vector operator-(vector v_old)
{
vector v_diff(xcoord-v_old.getx(), ycoord-v_old.gety(), zcoord-
v_old.getz());
return v_diff;
}
// Overload * - Scalar multiplication
vector operator*(double scalar)
{
vector v_scalar(xcoord*scalar, ycoord*scalar, zcoord*scalar);
return v_scalar;
}
// Overload / - Scalar division
vector operator/(double scalar)
{
vector v_scalar(xcoord/scalar, ycoord/scalar, zcoord/scalar);
return v_scalar;
}
// Overload += = Self-assigned Addition
vector operator+=(vector v_old)
{
xcoord+=v_old.getx();
ycoord+=v_old.gety();
zcoord+=v_old.getz();
}
// Overload -= Self-assigned Subtraction
vector operator-=(vector v_old)
{
xcoord-=v_old.getx();
ycoord-=v_old.gety();
zcoord-=v_old.getz();
}
// Overload *= Self-assigned Multiplication
vector operator*=(double scalar)
{
xcoord*=scalar;
ycoord*=scalar;
zcoord*=scalar;
}
// Overload /= Self-assigned Multiplication
vector operator/=(double scalar)
{
xcoord/=scalar;
ycoord/=scalar;
zcoord/=scalar;
}
// Overload * - Dot product
double operator*(vector v_old)
{
double dotProd((xcoord*v_old.getx())+(ycoord*v_old.gety() )
+(zcoord*v_old.getz()));
return dotProd;
}
// Overload ^ - Cross product
vector operator^(vector v_old)
{
vector v_cross((ycoord*v_old.getz())-(zcoord*v_old.gety()),
(zcoord*v_old.getx())-(xcoord*v_old.getz()),
(xcoord*v_old.gety())-(ycoord*v_old.getx()));
return v_cross;
}
}; //EVIL SEMI-COLON MUST STAY TO AVOID DAYS OF WONDERING WHAT IS WRONG
WITH YOUR HEADER!!!
Copyright © Alexander Livingstone, 2003
******* End Vector.h *****
Yes, I know it's newbie programming, and probably not worthy of a
copyright, but I'm proud of it
Thank you for the help.
Yours,
Alexander.
--
alex _dot_ livingstone *at* btinternet _dot_ com