daviddoria 334 Posting Virtuoso Featured Poster

passing by reference is when you want to do pass a variable to a function that you want to take a new value and be used back in the calling function, ie

int MyInt;
Function(MyInt);

cout << MyInt;

In this case, we pass MyInt to Function by reference, then we can use MyInt back in the calling function.

In you're case, you are trying to set the member variables of the class using the mutator function, so there is no need to pass or return anything!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

right, but i asked what
ul li
and
li li
are?

daviddoria 334 Posting Virtuoso Featured Poster

Hmm I think you're mistaken

You should do something like this

class TaxInfo
{

float totfedtax;
float totssitax;
float totstatetax
etc...
};

void Averager(TaxInfo &MyTax)
{
do stuff to MyTax.totfedtax, etc
}

see how clean it is!?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

What type is formGraphics? Are you using some kind of image library or something - ie what are you trying to draw on?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

whoa.. that's just asking for trouble. You should make a struct or a class to contain all that information and just pass around 1 variable, not 20!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

it looks like your set_add function is expecting you to pass it some values, but then you are reading them in from cin anyway, but then not doing anything with them.
Maybe you want something more like this:

void addressType::set_add()
{
    cout<<"Enter street address."<<endl;
string street;
    cin>>street;
    St_address = street;

    cout<<"Enter your city."<<endl;
string cit;
    cin>>cit;
    city = cit;

    cout<<"Enter your state."<<endl;
string st;
    cin>>st;
    state = st;

    cout<<"Enter the zip code."<<endl;
    cin>>zip;


    return;
}
daviddoria 334 Posting Virtuoso Featured Poster

Ok I'm getting there...
didn't you say you can apply it to multiple objects though? So couldn't it be like to make a "division" of the page that all uses btbx, like

<div class="btbx">
<p>Box 1</p>
<p>Box 2</p>
<p>Box 3</p>
</div>

If that's not right, then I guess my question has changed to what exactly is a "div" - in my examples, the properties were applied directly to the ul object

<ul class="sidemenu">

not to any "div" thing. haha sorry for the terrible terminology!

Thanks!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

so when it is good to use id vs class?

also, what does the id ("#") character mean when it comes after the name, like in

ul#sidebar

(vs #sidebar li)

?

Thanks!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

ah I see - dang that should be an error or a warning or something, shouldn't it??

daviddoria 334 Posting Virtuoso Featured Poster

Here is my demo.css

#sidebar {}

#sidebar ul {
list-style-image: url(images/bullet.gif);
}

ul {
list-style-type: circle;
}

and demo.html

<html>
<head>
<link  REL="StyleSheet" TYPE="text/css" HREF="demo.css"> 
</head>
<body>

<ul class="sidebar">
<li> Test1</li>
<li> Test2</li>
</ul>

<ul>
<li> Test3</li>
<li> Test4</li>
</ul>

</body>
</html>

I would expect the two items in the first list to have the image bullet.gif next to them, and the two items in the second list to have circles. What I actually see is that all 4 items have circles. The image file is in the correct place because if I move the list-style-image line to the ul{} they all have the image.

I think I'm just a little confused with the terminology I've been seeing.

What is the #? Maybe it's a class name? Sometimes I see sidebar.ul instead of #sidebar ul - is there a difference?

Thanks!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I am very new to css. I was looking at a css file I found online and trying to figure out what everything does. I am confused with the following couple of things. Please let me know if anything I say is wrong!

This on sets up some properties of a list item in a <div id="sidebar"> environment

#sidebar li {
	margin-bottom: 10px;
	background: url(images/img10.gif) no-repeat left bottom;
}

Now these two thing I was confused about:

#sidebar li ul {
	padding: 0 30px 40px 30px;
}
#sidebar li li {
	margin: 0;
	padding-left: 30px;
	background: url(images/img12.gif) no-repeat 5px 50%;
}

What is a li ul? and an li li?

Thanks!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Ok I found a different way (using iomanip.h)

stringstream IndexStream;
IndexStream << setfill('0') << setw(5) << Index;

This fixes the other memory error. My question remains though of why did the other way break??

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I am trying to output 00001 instead of just 1, so I do this:

char pos[5];
sprintf(pos, "%05d", 1);
string Index = (string) pos;

It works just as I'd expect - if I cout << Index it says 00001

However, it is breaking something totally unrelated. On the next line, I access an element of a vector

geom_Vector3 T = Translations[SceneIndex];

(Translations was declared as vector<geom_Vector3> and filled before any of this).

If I get one of the elements of the vector with the 3 sprintf lines commented, it works fine. If I run the 3 sprintf lines before accessing the element, it is filled with garbage.

1) Why is it doing this??
2) Is there a better, less "c style" way to turn an integer in to a 5 digit integer with leading zeros that will prevent this all together?

Thanks!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Is this flash (how do you tell?)
http://www.kwikkopy116.com/

Is there any way to develop a flash site on linux? I've been unable to find anything about it! If not, is there any other way to make a page like this that can be done on linux?

Thanks!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

bah I mis-typed again, I was trying to do

cout << a[0];

not

cout << a;

With the correct version, I do infact have to cast it as an int.

what is the difference between
cout<<static_cast<int>(a[0]);

and

cout << (int)a[0];

?

Thanks

Dave

daviddoria 334 Posting Virtuoso Featured Poster

awesome - thanks!

daviddoria 334 Posting Virtuoso Featured Poster

wow, thanks for the options. Someone else suggested I just use
map<vector<unsigned char>, int> ColorList;

Is that a bad idea? It seems like less work, but I didn't see it listed in your plethora of suggestions haha.

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

no, it is initialized (i guess I should have written that). I get the value from a function, ie.

unsigned char a[3];
glReadPixels(a); // puts data into a

cout << a;

It outputs a crazy character - I would like to see the value (0-255).

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I want to do something like this:

unsigned char r[3] = {255, 0, 0};
map<unsigned char[3], int> ColorList;
ColorList[r] = 1;

But I get the following:
error: array used as initializer

How else would I set the r element of the map?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

With printf, you specify the output type like this

unsigned char a;
printf("%u", a);

but with cout,

cout << a;

there is no type required. Do you have to cast the variable in order to see a reasonable output

cout << (int)a;

or something like that? How do you know which type to convert to? Ie when I do cout << a; I get some crazy ascii character, but what I wanted to see was a value between 0 and 255.

Thanks!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

ok, yea i was just trying to prevent having 2 maps because then when I want to update them (modify the contents) I'd have to do it in both maps.

So there is no built in thing to remedy this 2 map problem?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I would like to make a list of colors with an associated color index

ie

1, [1 0 0]
2, [0 1 0]
3, [.4 .4 .4]
etc

So I could make a map

map <int, double*> ColorMap;

Then I could look up the color by its index like this:

ColorMap[2]

However, I would also like to be able to get the index of a particular color, like this

double Color = [1 2 3];
ColorMap;

and have it give me back the index. Is there an easy way to make this two-way mapping?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

So that is a write() function, can you not do that with the actual << operator?

daviddoria 334 Posting Virtuoso Featured Poster

I see - thats what I meant by "too small", that when you dereference a derived class which is of type Aircraft* then you wouldn't get everything, but I guess that is correct!

Thanks for your help!
Dave

daviddoria 334 Posting Virtuoso Featured Poster

I'm convinced that works, but I'm still not sure why.

It is my understanding that when you make a pointer Aircraft* that a pointer is created which points to an address of the size required to hold all of the members of Aircraft. However, there are additional members (more than Aircraft) in Fighter because Fighter inherits all of Aircrafts members and then defines additional ones. So it seems that the Aircraft pointer would be "too small" to fit everything in Figher. Am I way off here?

daviddoria 334 Posting Virtuoso Featured Poster

right, but the problem is that the << operator is not a member function, so it is not inherited, right?

daviddoria 334 Posting Virtuoso Featured Poster

I still have the same question - why can you use

new Fighter

to assign an Aircraft variable?

daviddoria 334 Posting Virtuoso Featured Poster

hmm so even thought the pointer is a base*, you can use ptr = new V?

daviddoria 334 Posting Virtuoso Featured Poster

yea they do output the same information. So how do I make them inherit the operator?

daviddoria 334 Posting Virtuoso Featured Poster

I have a base class called ModelFile

I have derived classes called ObjFile and VtkFile that I would like both to use << from ModelFile.

However, since << is an external function,

ostream & operator << (ostream &output, const ModelFile &Model)
	{
		output << "Num Vertices: " << Model.NumVertices() << endl
				<< "Num Triangles: " << Model.NumTriangles() << endl;
		return output;
	}

The compiler doesn't know about

ostream & operator << (ostream &output, const ObjFile &Obj)

Is there a way to do this?

Thanks,
Dave

daviddoria 334 Posting Virtuoso Featured Poster

I would like to declare the type of an object based on user input.

Ie. I would like to do the following:

string obj = //get from command line arguments
	if(Format == "obj")
	{
		ObjFile Obj;
		Obj.Read(InputFile);
		Obj.DoSomething();			
		Obj.Write(OutputFile);
	}

	else if (Format == "vtk")
	{
		VtkFile Vtk;
		Vtk.Read(InputFile);
		Vtk.DoSomething();
		Vtk.Write(OutputFile);
	}

//the list goes on...

But to possibly 10-ish file types, without having a 5 page long list of if's. Is this possible? Something like

//somehow make an object of the correct type called GoodObject
GoodObject.Read(InputFile);
GoodObject.DoSomething();
GoodObject.Write(OutputFile);

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I've spend a lot of time working on a bunch of classes (point, vector, ray, triangle, plane) etc to work with these objects and their intersections in c++. However, now that I am ready to do a full scale project with them, I am finding they are terribly slow! I've look around online and found a handful of things like this, but I was wondering if there was kind of an "industry standard" one that I should use so that if I share code with other people they will already have the libraries installed and be familiar with the notations/function names.

Thoughts on this?

Thanks,
Dave

daviddoria 334 Posting Virtuoso Featured Poster

actually one more thought

If there are multiple derived classes which need to update the triangles, then the function has be to implemented (copied and pasted) into each of them. This sounds like a bad thing to do, no?

daviddoria 334 Posting Virtuoso Featured Poster

ah great - i see.

I'll get this OOP thing eventually.. haha

daviddoria 334 Posting Virtuoso Featured Poster

I have a base class called "ModelFile" which I derive several types of 3D model file classes from.

Many of these types of files are just a set of points, so in the base class I have a vector<Point> member. Some of the derived file classes also have vector<Triangle> members. The problem is, in a class with triangles, if I move the points, I need to update the triangles (even if the triangles have their 3 points stored as the address of the points, I still need to recalculate normals). I thought of two solutions:

1) put the vector<Triangle> in the base class so I can call an UpdateTriangles() function every time a MovePoints() function is called (which is in the base class). The vector<Triangle> would just be empty for derived classes without triangles and therefore the update triangle function would have nothing to do in those cases.

2) is there a way to somehow flag/trigger something to happen in particular derived classes? ie when MovePoints() is called, at the end of the function say "if the current class is a derived class with triangles, do soemthing"?

Any suggestions are appreciated!

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I have a Triangle class which has members

Point P1, P2, P3;

So generally I pass the constructor 3 points.

Point A(1,1,1);
Point B(1,1,0);
Point C(0,0,1);
Triangle T(A,B,C);

Then I have a bunch of functions that I can pass point's to such as to find intersections and distances etc.

However, now I would like to make a triangle which stores pointers to points, so that when I change the positions of the points, the triangle is automatically updated.

Ie.

Point A(1,1,1);
Point B(1,1,0);
Point C(0,0,1);
Triangle(&A, &B, &C);

This way when I do

A.setX(3);

The triangle now thinks the points (3,1,1), (1,1,0), (0,0,1) are its three points.

Is there some way to do this dual functionality in one class? Or do I need to make a ValueTriangle and a PointerTriangle class?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

ah so silly... its pretty hard to keep track of those tags because html (for some reason) doesn't seem to complain if there are extra, or too few! seems like that should generate a "compiler error".

Guess I just have to get used to it!

Thanks
Dave

daviddoria 334 Posting Virtuoso Featured Poster

I found this - seems pretty nice so far

http://www.phpjunkyard.com/php-click-counter.php

Thanks for the other recommendations!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

peter_budo: that looks cool, but seems like WAY overkill for what i'm trying to do

if this can indeed be done with a simple php script, can one of the admins please move this to php as mexabet suggested?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I have done some html many years ago, but never css. I downloaded a template
http://www.freecsstemplates.org/preview/exposure

But something has gone slightly wrong. When I use it on my website
http://doriad.myrpi.org/

you can see that the bottom "grey" bar is above the blue line, where in the example the grey is kind of the whole background. Can anyone briefly explain why that may be?

Thanks!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Does anyone know how I can count how many times a pdf has been downloaded from my site? Maybe someone has a php script or something that does this?

Thanks!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Nope, I don't think it can be done the way I would like. I got it to compile with a static member function, but then I can't access non static data members, so that defeats the point!

daviddoria 334 Posting Virtuoso Featured Poster

So I just have to use the next integer number of bytes? I'm not too sure about how big data types are, but say a double is 2 bytes.

double d;
infile.read(reinterpret_cast < char * > (&d), sizeof(d));

This will read 16 bits... so now I have read too many bits. Then I have to manually split the byte and store the first half with the current byte and save the last half to put with the next byte? That sounds really painful...

Maybe I am thinking about this wrong?

Thanks,
Dave

daviddoria 334 Posting Virtuoso Featured Poster

but that is 12 bytes right? I need 12 bits.

And should I open the file as ios::binary or not?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I need to do something like this:

ifstream infile(Filename.c_str());
//ifstream infile(Filename.c_str(), ios::binary);
string line;

///////////// Read Header ////////////
//read magic number
getline(infine, line);
	
while(line[0] == "#")
	getline(infile, line);
MagicNumber_ = line;

//more ascii stuff ......

//start reading binary data
int m;
infile.read(reinterpret_cast < char * > (&m), sizeof(m));

Can I do the above (ie. read with getline() and then read binary? Also, that will read 1 byte (8 bits) into an int (is there an easier way?). How would I read 12 bits at a time (for a 12-bit color image)?

Thanks!

David

daviddoria 334 Posting Virtuoso Featured Poster

What error are you getting?
The problem with both of those solutions, in my opinion, is that you then cannot access member variables, which was my whole point of doing this in a class! (the display() function can only take certain parameters, so you cannot pass it anything else, you have to make the information global.)

Does this make sense?

daviddoria 334 Posting Virtuoso Featured Poster

ok cool, i'll give it a try

thanks everyone

daviddoria 334 Posting Virtuoso Featured Poster

I see, that makes sense.

What I was trying to do was this:

make a Plot class that would have all mouse selection routines (like rotation and zooming) defined and have everything else for opengl setup but then have a virtual Display() function so the user can override what actually gets plotted.

How else would I go about doing this since I have to provide glutMouseFunc and glutDisplayFunc with function pointers to be used when those callbacks are called?

Thanks,
Dave

daviddoria 334 Posting Virtuoso Featured Poster

As I mentioned, I can't overload the function because it is not mine, it is in the glut library!

daviddoria 334 Posting Virtuoso Featured Poster

I actually don't have control over glutMouseFunc (I mean I suppose I could edit the glut source, but that sounds like a bad idea)

Why is it so much different to pass a member function than a normal function?

Is there no way to do this without overloading glutMouseFunc?

Thanks!

Dave