Jump to content

Hdk Basics


Recommended Posts

  • Replies 84
  • Created
  • Last Reply

Top Posters In This Topic

Strange indeed... you must be doing something wrong...

UT_Vector4::length() just runs ::dot() on the argument and itself. But a 4-vector represents homogeneous coordinates, so a 4-component dot product ain't the same as a 3-component one (likely, it will return a value which is bigger by 1).

Then there is the normalize() issue. Looking at its definition, you'll realize that it normalizes *itself* -- it does the normalization "in place" (modifies itself so as to have a length of 1) and UT_Vector3 returns (for convenience) its current length squared, whereas UT_Vector4::normalize() returns nothing.

But given that you don't specify the type for either rvec or nrvec in your code snippet, it's hard to tell exactly what brand of catastrophe the statement nrvec = rvec.normalize(); is actually causing ;) (even though I'm not an experienced programmer, I think I can safely say that types are very important in C++ -- keep track of them at all times).

Anyway. I'm pretty sure I know what you're trying to do ;) so, reading between the lines a little, here's a possible fix:

//... include all the proper headers, etc...//
//...//

// vec4-to-vec3 truncation via UT_Vector3::operator=(UT_Vector4 const &);
UT_Vector3 rvec  = ppt_emitter->getPos() - ppt_receiver->getPos();

// length squared since you might need it for other tests...I think;)
fpreal     d2    = dot(rvec,rvec)+1e-9; //tiny offset to avoid 0-length

// stuff that makes use of d2 and the full-length rvec goes here... maybe...

// Now make rvec unit length, and use it in the dot product stuff... perhaps...
rvec /= SYSsqrt(d2);

//...//

Hope that helps.

Link to comment
Share on other sites

Thanks, Mario. I think that helps.

At least I am digging the code now

Could be the possible reason that the things go wrong the way I cycle my points?:

...

GEO_Point *ppt, *emit_ppt;

...

FOR_ALL_GPOINTS(gdp, ppt)

{

...

FOR_ALL_GPOINTS(emit_gdp, emit_ppt)

{...}

...

}

or it's fine?

And, btw, should be points' position (eP, rP)of UT_Vector3 or UT_Vector4 type?

Thanks.

Link to comment
Share on other sites

I think it's WAY better now, then it was.

Another question - how can I control the precision of variables?

I think the result of some multiplications exeeds normal ranges and I get something like -0.179462e-18 and I am not sure how Houdini interprets this in its turn - So I think I would be happy to render such numbers as, say 4 digits after point, i.e. -0.1794. What do you say?

And how can I achieve this?

Thanks.

Link to comment
Share on other sites

I think the result of some multiplications exeeds normal ranges and I get something like -0.179462e-18  and I am not sure how Houdini interprets this in its turn - So I think I would be happy to render such numbers as, say 4 digits after point, i.e. -0.1794.  What do you say? 

And how can I achieve this?

The value -0.179462e-18 is scientific notation for a decimal point followed by 18 zeros and then the value 179462. In other words, it is a compact way of writing the value -0.000000000000000000179462, which you can safely read as simply "zero". And which as you can see, is not at all the same as "-0.1794". So no, please don't feel "happy to render such numbers as, say 4 digits after point".

I think this question should be a simple one.

vect = Pemit - Preciev;

Is it, in a general case, a vector FROM emitter or TO emitter?

There is no "general case" here; it is what the expression makes it, which in this case can be interpreted as a vector FROM the receiver TO the emitter, but whose origin is at {0,0,0} -- i.e: a "free" vector. Meaning that the expression Preceiv + vect will have a value exactly equal to Pemit.

Hope that makes some sense.

Link to comment
Share on other sites

Hi,

I need to create an array of pointers, pointing at different ppt. Then I want to access different points' attributes via my array of pointers (as if I was dealing with normal ppt).

What type of should be my array? The same as ppt(which is GEO_Point) or something different?

What is the maximum size of such array, are there any limits?

And the second question. How can I destroy such array when I don't need it any more? Or will it be destroyed automatically?

Thanks.

P.S. I am trying to develope a hand-made kd_tree_kind_of_structure - so that I could make a kind of array of ponts and sort them as I want.

Link to comment
Share on other sites

What type of should be my array?  The same as ppt(which is GEO_Point) or something different?

Depends on what you want. "GEO_Point *" is certainly the most flexible.

What is the maximum size of such array, are there any limits?

You can make use of <UT/UT_PtrArray.h>. It's dynamically resizeable. Thus if you choose GEO_Point pointers as your base type, your variable becomes:

UT_PtrArray&lt;GEO_Point *&gt; myPointArray;

And the second question.  How can I destroy such array when I don't need it any more?  Or will it be destroyed automatically?

It's destroyed automatically with UT_PtrArray when the object instance destructs.

Link to comment
Share on other sites

UT_PtrArray&lt;GEO_Point *&gt; myPointArray;

It's destroyed automatically with UT_PtrArray when the object instance destructs.

20033[/snapback]

That's very valuable, edward, thanks.

A small question - do I still have to initialize my array and its bounds presizely? I.e. do I have to initialize my array as:

UT_PtrArray&lt;GEO_Point *&gt; myPointArray[8][8][1000];

or can I just initialize it as :

UT_PtrArray&lt;GEO_Point *&gt; myPointArray;

- and then, later in the code, assign the members of the array, like

for(i=1;i&lt;=100;i++)
{
myPointArray[i]=my_var;
}

?

Thank you.

Link to comment
Share on other sites

UT_PtrArray<GEO_Point *> myPointArray[8][8][1000];

UT_PtrArray<GEO_Point *> myPointArray;

The first line is doing something completely different than the second line. Here you initialize a fixed size 3-dimensional array of UT_PtrArrays. So taking into account, that UT_PtrArray is a 1-dimensional data structure, You have 4 dimensional totally.

In the second line you allocate 1 UT_PtrArray (instead of 64000 above). So you have one 1-dimensional data structure. But your array has a length of zero. You can specify the size of the array in the constructor of UT_PtrArray:

UT_PtrArray<GeoPoint*> myPointArray(100);

Here 100 is passed on to the sz parameter of the constructor. This will set the initial size of the array to 100.

So square brackets always allocate a number of objects of the given type. Parentheses pass the values to the constructor.

To make a long explanation short:

UT_PtrArray <GeoPoint*> myArray1[100];

and

UT_PtrArray <GeoPoint*> myArray1(100);

are two different things. The first allocates 100 UT_PtrArrays with zero entries, while the second one allocates one array with 100 entries.

Link to comment
Share on other sites

If you intend to modify the points, then:

GEO_Point *ppt;
GEO_PointList &amp;pl = gdp-&gt;points();
unsigned      npt = pl.entries();
for(unsigned i=0;i&lt;npt;i++) { ppt=pl[i]; /*...*/ }

Or, alternatively...

GEO_Point *ppt = gdp-&gt;points().head();
while(ppt) { /*...*/ ppt=ppt-&gt;next(); }

Of course, if you just want to read the points, you should use the const versions of those:

GEO_Point const *ppt;
GEO_PointList const &amp;pl = gdp-&gt;points();
//...//

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

is there a standard way to get a point number?

I need to do the following:

FOR_ALL_PRIMITIVES(gdp, prim)//here I need to cycle all faces of my geo

{

ofstream f("file.txt", ios::app);

//here I plan to somehow cycle all points of a face

(

f << "Face's points" << _point_number_ << endl;

)

}

Any ideas how to do it?

Thanks.

Link to comment
Share on other sites

Or another question -

1)How can I cycle through points of a certain face (primitive)?

2)Is there an easy way to get the number of primitives in a gdp, similar to points?

(e.g.

GEO_PointList &pl = gdp->points();

unsigned npt = pl.entries();

)

Thanks

Link to comment
Share on other sites

untested example ...

int vertex_count;
int i;
GEO_Primitve *prim;

cerr &lt;&lt; "Number of primitives: " &lt;&lt; gdp-&gt;primitives().entries() &lt;&lt; endl;
FOR_ALL_PRIMITIVES(gdp, prim)
{
    cerr &lt;&lt; "Primitive #" &lt;&lt; prim-&gt;getNum() &lt;&lt; ": ";
    vertex_count = prim-&gt;getVertexCount();
    for( i = 0; i &lt; vertex_count; i++ )
    {
        const GEO_Vertex &amp;vertex = prim-&gt;getVertex(i);
        GEO_Point *pt = vertex.getPt();
        UT_ASSERT( pt );
        cerr &lt;&lt; pt-&gt;getNum() &lt;&lt; " ";
    }    
    cerr &lt;&lt; endl;
}

Link to comment
Share on other sites

Any of the functions in GEO_Detail, GU_Detail, etc are fair game so you really should try to familiarize yourself with those headers. Off the top of my head transform() should work.

20521[/snapback]

ok, I've played with transform() a little bit, but I don't seem to make it work:

UT_Matrix4 mat(1,1,1,1,

1,1,1,1,

1,1,1,1,

0,0,0,0);

gdp->transform(mat,

0,

0,

0,

1,

1,

1,

0,

0);

has anybody got an example how to make it work properly?

Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...