GeAutoDynamicArray
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/12/2012 at 03:45, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R14
Platform: Windows ;
Language(s) :---------
Hi Folks,
I have a GeAutoDynamicArray that I'm playing about with, but I'm having all sorts of troubles with not being able to set values correctly. My basic array setup is below - there's a bit missing to keep code size down (just some if's and else's etc), but this is the base setup. For the example below I've used 3 index's that can store reals. All index in the array are filled with something, even if it's "0".
----- in EXECUTE function -----
GeAutoDynamicArray<float> MyArray(Array_Count); // Array_Count = LONG taken from user data
// then I have my 'for" statement down the code a bit (still in EXECUTE though) :
for(int cnt=1;cnt<=Array_Count) // a new array is made for each Array_Count value.... this ok so far?
{
MyArray.ReSize(cnt); // increase array to the size of Array_Count
MyArray[cnt] = MyArray.Insert(25,0) // 1st index
MyArray[cnt] = MyArray.Insert(0,1) // 2nd index
MyArray[cnt] = MyArray.Insert(12,2) // 3rd index
cnt++; //
}
----- END EXECUTE etc -----
Now, when I add to the Array_Count LONG, the array is putting a "1" into the equivalent LONG number's index count. For example, if the Array_Count = 1, then a 1 is put into MyArray.Insert(1,0) instead of 25 for the first index. If Array_Count = 2, then MyArray 2nd index becomes MyArray.Insert(1,1) instead of (0,1) etc. And also the first index goes back to being 25. Hope that makes sense...
What could be/is going on here? regards,
WP. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/12/2012 at 04:16, xxxxxxxx wrote:
Your code (please use tags) has no sense.
GeAutoDynamicArray.Insert() returns a Bool to tell if the value is actually inserted. Furthermore for a single loop you assign 3 times the same value to an index in the array.
If you insert the items, you don't need to resize the array; it's only needed if you want to assign directly index values with the operator []. (With a GeAutoDynamicArray this is event not need as it's an auto dynamic array. )Also please use CINEMA types: Real instead of float, LONG instead of int etc.
Here's what your code could be:
LONG count = 1; GeAutoDynamicArray<Real> autoDynArray(count); for(LONG i=0; i<count; i++) { autoDynArray.Insert(25, 0); autoDynArray.Insert(0, 1); autoDynArray.Insert(12, 2); }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/12/2012 at 04:42, xxxxxxxx wrote:
If you use Insert with fixed Index why do you need this loop at all?
const LONG count = 3; GeAutoDynamicArray<Real> autoDynArray(count); autoDynArray.Insert(25.0, 0); autoDynArray.Insert(0.0, 1); autoDynArray.Insert(12.0, 2);
or this
const LONG count = 3; GeAutoDynamicArray<Real> autoDynArray(0); for(LONG i=0; i<count; i++) { autoDynArray.Insert(25.0, i); }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/12/2012 at 07:42, xxxxxxxx wrote:
Also a word of warning from me about the GeAutoDynamicArray.
The Auto version is a bad one to use when you're experimenting with arrays and haven't gotten your code locked down. Or if you are a newish code writer like me.
After doing a bit of array work with it recently I discovered that this array will do unexpected things to the indexing of itself if you do too many things to it like Insert, Push, etc...If you're going to be doing a lot of array manipulation beyond the simple adding or subtracting from the end of the array. Then I personally recommend using the GeDynamicArray instead. That way you won't run into any surprises with the array indexing.
You'll have to free the memory by hand: gDelete(myArray);
But IMHO I think it's worth the trouble. Because the indexes will always be what you expect them to be at all times. With no surprises.When you're already struggling with figuring out the code for other tasks. The last thing you need is an array automatically changing it's indexing secretly in the background. And tricking you into thinking you have a bug in your other code.
A lesson learned by me the hard way.-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/12/2012 at 08:11, xxxxxxxx wrote:
Actually if using new C4D SDK then datastructures from c4d_misc are better alternative.
BlockArray or BaseArray would be alternative for his case.I think that using gDelete or gNew is a bad idea in most cases in the main code.
They should be hidden in some data structures. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/12/2012 at 09:31, xxxxxxxx wrote:
^You're the second person I've heard say good things about the new arrays in R14.
I'm still coding for R12 & R13 so I can't use them. But I will definitely look at them if I ever get a chance to code things for R14. They sound like a nice addition to the SDK.-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/12/2012 at 09:49, xxxxxxxx wrote:
c4d_misc can use some important C++11 features like move semantics and this is huge benefit.
Actually it should be possible to copy c4d_misc to R13 SDK and use it then.
The only question now is what is better to use new std or c4d_misc ?
If you need something like unordered_map then there is no alternative in c4d_misc for now. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/12/2012 at 17:08, xxxxxxxx wrote:
Thanks everyone,
I'm definately a 'noobie' at all this too Scott!! In the 3D game, programming is not my native tongue
I'm wishing to have a table built of arrays, hence why I had the for loop. I thought the resize would make another row in the table (so to speak) made of the initial array setup. I'm feeling this isn't the case.
I want an array Or something of the like) like the below:
row 1 [index 1] [index 2] [index 3] and so on for whatever amount I need (at this stage possibly 16).
Then I want to be able to add a row and fill it with the data as I go and as needed. So it could end up like the following:
row 1 [index 1] [index 2] [index 3]
row 2 [index 1] [index 2] [index 3]
row 3 [index 1] [index 2] [index 3]
row 4 [index 1] [index 2] [index 3]
And so on as needed by the plugin. I thought the ReSize was a bit like adding another row. So in my initial example, if the Array_Count = 5, then there would be 5 rows made, and hence the loop to set it up. If it changed (through user interaction) to 6, then the array should resize to 6 rows. My take on it was that the auto array kind of added another row...
I did some Googling etc but not being native at coding, it sounds like I've misunderstood what I read. How can I go about creating a table array then, or a c++ element of such that works in a table kind of fashion? It needs to be changeable, and if possible accessible by other objects.
WP. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/12/2012 at 18:51, xxxxxxxx wrote:
You don't use an array to make a table.
Tables are created by using nested loops. At least that's the common way to do it.Raw C++ EXAMPLE:
#include<iostream> using namespace std; int main () { //When the innermost loop finishes looping. The next outter loop runs...and so on... //You work from the inside loop and work your way out till the first for loop returns FALSE for(int col1=0; col1<1; col1++) { for(int col2=0; col2<1; col2++) { for(int col3=0; col3<3; col3++) //This loops three times creating three rows of data { cout<< col1 <<" "<< col2 << " " << col3 <<endl; } } } system ("pause"); // wait for user to close the output window return 0; }
An array produces a linear result. Or in other words. A row of data.
If you wanted to create a table of arrays. Then you'll need to create nested loops with an array inside of each nested for loop.
But if you just wanted to create a table of data. You don't need an array at all.-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 19/12/2012 at 01:37, xxxxxxxx wrote:
Originally posted by xxxxxxxx
c4d_misc can use some important C++11 features like move semantics and this is huge benefit. Actually it should be possible to copy c4d_misc to R13 SDK and use it then.The only question now is what is better to use new std or c4d_misc ?If you need something like unordered_map then there is no alternative in c4d_misc for now.
If you need an unordered map, the hashmap in c4d_misc should do the job.
Best regards,
Wilfried
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 19/12/2012 at 03:36, xxxxxxxx wrote:
Apparently what you need it a 3D array.
One comfortable but slow way to do this is to use array of array of array.BaseArray<BaseArray<BaseArray<Real>>>
Faster way to do this is to use 1d array and pack 3d inside.
way.BaseArray<Real>
const LONG xres = 8; const LONG yres = 8; const LONG zres = 8; BaseArray<BaseArray<BaseArray<Real>>> float_3x_array; //slow way float_3x_array.Resize(zres); for(LONG z=0; z<zres; ++z) { float_3x_array[z].Resize(yres); for(LONG y=0; y<yres; ++y) { float_3x_array[z][y].Resize(zres); for(LONG x=0; x<xres; ++x) { float_3x_array[z][y][x] = z*100.0 + y*10.0 + x; } } } BaseArray<Real> float_3d_array; //faster way float_3d_array.Resize(xres*yres*zres); //lambda function to translate 3d coordinates to 1d array coordinates. auto index3d = [&](LONG z, LONG y, LONG x) -> LONG { return ((z*yres + y)*xres) + x; }; for(LONG z=0; z<zres; ++z) { for(LONG y=0; y<yres; ++y) { for(LONG x=0; x<xres; ++x) { //float_3d_array[ ((z*yres + y)*xres) + x ] = z*100.0 + y*10.0 + x; float_3d_array[ index3d(z,y,x) ] = z*100.0 + y*10.0 + x; } } } for(LONG z=0; z<zres; ++z) { for(LONG y=0; y<yres; ++y) { for(LONG x=0; x<xres; ++x) { //if(float_3x_array[z][y][x] != float_3d_array[ ((z*yres + y)*xres) + x ] ) GePrint(" NOT OK "); if(float_3x_array[z][y][x] != float_3d_array[ index3d(z,y,x) ] ) GePrint(" NOT OK "); } } }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 19/12/2012 at 03:39, xxxxxxxx wrote:
Yes I forgot about HashMap, may be because it is not in MiscTest inside.
Now the question is how to use it optimally this way?
HashMap<String,String>
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/12/2012 at 03:08, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Yes I forgot about <span style="color:#2b91af;">HashMap</span>, may be because it is not in MiscTest inside.Now the question is how to use it optimally this way?
<span style="color:#2b91af;">HashMap</span><String,String>
If you really want to use a string as key, have a look at hascode.h, which is include in c4d_misc too.
It contains an implemenation for generating keys based on C strings. Depending on the data format of the string class (e.g. UTF16) - and the speed you want/have to achieve (CRC might create very good hashes, but often CRCs are too slow) - you have to add additional methods for the key generation.
Best regards,
Wilfried
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/12/2012 at 04:27, xxxxxxxx wrote:
Yes I really need C4D String as a key.
Of course the Hash should be as fast as possible, so I use now my own modified String class witch my own Hash code for this.
Just curious why this is not included into SDK?
Are cases who String will be use as a key so rare ? -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/12/2012 at 22:07, xxxxxxxx wrote:
Thanks Everyone for your contributions.
I've been busy Googling and trying to work my way around with the suggestions provided, to which I may have come up with a solution. I'm going to need to do some further experiments to see if it operates the way I had in mind - but thus far it seems to be OK...
Cheers,
WP.