Create Array for Vertexmap?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/08/2009 at 15:17, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   10.1+11 
Platform:   Windows  ; Mac  ;  
Language(s) :     C++  ;

---------
Hi,

maybe a very basic question, but here it is anyway:

I want to store a lot of values (real, between 0..1) in an array, and write that array to a vertex map (VariableTag).

The VariableTag has a method "void* GetDataAddressW(void)", which can be casted into an array of Real pointers. Can I somehow create a similar array myself and copy it into the VariableTag's array if needed?

Thanks in advance for help!

Cheers,
Jack

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/08/2009 at 15:45, xxxxxxxx wrote:

When you get the data address for writing, simply write your array values to the data address array. It is just a pointer to the VertexMap tag's actual array.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 19/08/2009 at 06:10, xxxxxxxx wrote:

I know, but that would mean to allocate the tag first. Since allocatoin costs time, I only want to do this if it's necessary.

Is there now way to prepare the array and only allocate the tage & copy the data into it, when required?

Since I will have to do this with several tags and quite large numbers of vertices, I am afraid it would decrease the performance too much. Or is allocation of a tag & filling the data into it not that slow?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 19/08/2009 at 06:17, xxxxxxxx wrote:

I am not sure I understand the question. If it is just about the array allocation, that would be something like this:

> \> Real \*buffer = (Real\* )GeAlloc(length\*sizeof(Real)); //length == length of the array \> \> //do something \> \> GeFree(buffer); \>

cheers,
Matthias

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/08/2009 at 16:42, xxxxxxxx wrote:

Ah, that sounds reasonable 🙂

And this array can be copied into the Vertexmap's Data array, if needed?

Thanks!

Greetings,
Jack

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/01/2010 at 18:40, xxxxxxxx wrote:

I'm having a horrible time trying to generate a Tvertexmap tag and fill it with an array. I seem to be able to make the tag just fine useing maketag or the Allocation below, but actually populating it with data... I'm just moving over from COFFEE to C++ and have no solid idea how to construct an array from scratch in C++ nor of how to point the tag to the correct address... I'm also not sure if I need to Free any of the junk I create in a case like this since C4D should take over ownership of the tag... If I'm building the array by parsing an external file, will I need to Free() that array once the vertexmap tag gets put into the document? Here is what I've tried so far- I can make the tag, but I can't seem to access the data- I've left a couple of attempts in the code below:

static VariableTag*vMtag = VariableTag::Alloc(Tvertexmap, 20); // the 20 seems to have no effect there are no points in the vertex map of the structure manager
                //pCombX=(Real* )vMtag->GetDataAddressW(); // this seems to point to a read-only array
                const void *dataptr = vMtag->GetDataAddressW(); // This was a read-only array in the PluginCafePost I swiped it from
                dataptr[3] = 179; // this says I'm trying to do arithmatic on a void
               // VariableTag *vMtag = VariableTag::Alloc( Tvertexmap );
                vMtag->SetName("gGreen"); // this works great!
                objCellMembrane->InsertTag(vMtag, NULL); // this works great too
                GePrint("pCombx 21: " + RealToString(pCombX[21]) );// this prints pCombx21: 0"
                GePrint("pCombx 3: " + RealToString(pCombX[3]) ); // this prints pCombx3: 0"
                doc->AddUndo( UNDO_NEW, vMtag ); // would I need to free anything after this?
Thanks,
G

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 27/01/2010 at 06:54, xxxxxxxx wrote:

Here is a simple example how to create and fill a vertex map tag. The code should be pretty much self explainatory.

  
Bool MenuTest::Execute(BaseDocument *doc)  
{  
  StopAllThreads();  
  
  //get active object and check if it is a polygon object  
  BaseObject *op = doc->GetActiveObject();  
  if (!op || op->GetType() != Opolygon) return FALSE;  
  
  //get the object's vertex (point) count  
  LONG pcnt = ToPoly(op)->GetPointCount();  
  
  //create the vertex map tag.  
  VariableTag *vtag = (VariableTag* )op->MakeVariableTag(Tvertexmap, pcnt, NULL);  
  if (!vtag) return FALSE;  
  
  op->Message(MSG_UPDATE);  
  
  //get the vertex map tag's size (should be same as vertex (point) count  
  LONG vcnt = vtag->GetDataCount();  
  //get the pointer to the vertex map array  
  Real *vmap = (Real* )vtag->GetDataAddressW();  
  
  //random class to fill vertex map with random values, just to show how to fill the vertex map  
  Random rnd;  
  rnd.Init(46346);  
  
  //fill the vertex map with random values  
  if (vmap)  
  {  
      for (LONG i=0; i<vcnt; i++)  
      {  
          vmap[i] = rnd.Get01();  
      }  
  }  
  
  vtag->Message(MSG_UPDATE);  
  
  EventAdd();  
  
  return TRUE;  
}  

cheers,
Matthias

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 28/01/2010 at 10:03, xxxxxxxx wrote:

Perfect Matthias- I learned a lot from this and got it up and running right away. Thank you very much!