A
{AGUT2} {H}-IWIK
Hi,
I'm trying to pass my vector to a function external to my main(), but my
compiler is complaining. FYI, the struct for the facetInfo works perfectly,
it's just the vector passing.
A quick overview... I have four sets of co-ordinates in each 'facetInfo',
and a vector of 'facetInfo's. I want to strip those 'facetInfo' objects
that have y-values of zero (.v1y, .v2y and .v3y), and return a 'facetInfo'
vector with the remaining 'facetInfo's into my main().
Here's a stripped down version....
****** Begin Code Snippet ******
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
// Creates the basic framework for the facets to be read in
struct facetInfo {
double v1x;
double v1y;
double v1z;
double v2x;
double v2y;
double v2z;
double v3x;
double v3y;
double v3z;
double nox;
double noy;
double noz;
}; // Semicolon necessary
int main()
{
vector<facetInfo> mySurface;
facetInfo holdMe; // Holder facet to allow push_back() function.
ifstream inf("input.stl");
char buffer[128]; // File input buffer - 128 letter maximum
while(!inf.getline(buffer, 128, ' ').eof())
{
... // fills mySurface with 'mySurface.push_back(holdMe);'s
}
}
vector<facetInfo> cutZeros(vector<facetInfo> mainHull)
{
facetInfo holder;
int goFor = mainHull.size();
int atNum = 0;
vector<facetInfo> newHull;
while (atNum<goFor)
{
if (mainHull.v1y != 0)
{
if (mainHull.v2y != 0)
{
if(mainHull.v3y != 0)
{
holder.v1x = mainHull.v1x;
holder.v1y = mainHull.v1y;
holder.v1z = mainHull.v1z;
holder.v2x = mainHull.v2x;
holder.v2y = mainHull.v2y;
holder.v2z = mainHull.v2z;
holder.v3x = mainHull.v3x;
holder.v3y = mainHull.v3y;
holder.v3z = mainHull.v3z;
holder.nox = mainHull.nox;
holder.noy = mainHull.noy;
holder.noz = mainHull.noz;
newHull.push_back(holder);
} // end3 if
} // end2 if
} // end1 if
atNum++;
} // endwhile
return newHull;
}
****** End Code Snippet ******
The compiler says 'v1x' [and all the others] is not a member of
'vector<facetInfo,allocator<facetInfo> >' in function
cutZeros(vector<facetInfo,allocator<facetInfo>>)
Now, I read something about changing the cutZeros function to:
****** Begin Code Snippet ******
// line into main() after teh while loop
vector<facetInfo>& facinf = mySurface;
// out of main()
vector<facetInfo> cutZeros(const facetInfo& f)
{
facetInfo holder;
int goFor = mainHull.size();
int atNum = 0;
vector<facetInfo> newHull;
...
return newHull;
}
****** End Code Snippet ******
But the compiler says that 'size' is not a member of 'facetInfo' in
function 'cutZeros(const facetInfo &)'
Am I able to do this, or am I living in false hope?
Thank you again for your help, c.l.c++ - When I have a modicum of skill I
will pay your kindness back
Alex Livingstone
I'm trying to pass my vector to a function external to my main(), but my
compiler is complaining. FYI, the struct for the facetInfo works perfectly,
it's just the vector passing.
A quick overview... I have four sets of co-ordinates in each 'facetInfo',
and a vector of 'facetInfo's. I want to strip those 'facetInfo' objects
that have y-values of zero (.v1y, .v2y and .v3y), and return a 'facetInfo'
vector with the remaining 'facetInfo's into my main().
Here's a stripped down version....
****** Begin Code Snippet ******
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
// Creates the basic framework for the facets to be read in
struct facetInfo {
double v1x;
double v1y;
double v1z;
double v2x;
double v2y;
double v2z;
double v3x;
double v3y;
double v3z;
double nox;
double noy;
double noz;
}; // Semicolon necessary
int main()
{
vector<facetInfo> mySurface;
facetInfo holdMe; // Holder facet to allow push_back() function.
ifstream inf("input.stl");
char buffer[128]; // File input buffer - 128 letter maximum
while(!inf.getline(buffer, 128, ' ').eof())
{
... // fills mySurface with 'mySurface.push_back(holdMe);'s
}
}
vector<facetInfo> cutZeros(vector<facetInfo> mainHull)
{
facetInfo holder;
int goFor = mainHull.size();
int atNum = 0;
vector<facetInfo> newHull;
while (atNum<goFor)
{
if (mainHull.v1y != 0)
{
if (mainHull.v2y != 0)
{
if(mainHull.v3y != 0)
{
holder.v1x = mainHull.v1x;
holder.v1y = mainHull.v1y;
holder.v1z = mainHull.v1z;
holder.v2x = mainHull.v2x;
holder.v2y = mainHull.v2y;
holder.v2z = mainHull.v2z;
holder.v3x = mainHull.v3x;
holder.v3y = mainHull.v3y;
holder.v3z = mainHull.v3z;
holder.nox = mainHull.nox;
holder.noy = mainHull.noy;
holder.noz = mainHull.noz;
newHull.push_back(holder);
} // end3 if
} // end2 if
} // end1 if
atNum++;
} // endwhile
return newHull;
}
****** End Code Snippet ******
The compiler says 'v1x' [and all the others] is not a member of
'vector<facetInfo,allocator<facetInfo> >' in function
cutZeros(vector<facetInfo,allocator<facetInfo>>)
Now, I read something about changing the cutZeros function to:
****** Begin Code Snippet ******
// line into main() after teh while loop
vector<facetInfo>& facinf = mySurface;
// out of main()
vector<facetInfo> cutZeros(const facetInfo& f)
{
facetInfo holder;
int goFor = mainHull.size();
int atNum = 0;
vector<facetInfo> newHull;
...
return newHull;
}
****** End Code Snippet ******
But the compiler says that 'size' is not a member of 'facetInfo' in
function 'cutZeros(const facetInfo &)'
Am I able to do this, or am I living in false hope?
Thank you again for your help, c.l.c++ - When I have a modicum of skill I
will pay your kindness back
Alex Livingstone