RSS

Using the ISwColorContour interface

14 Jul

Override the function

public int Value(object face, ref float vertexCoords, ref float normalCoords, out double Value)

{

}

Now the problem comes. In the documentation, it says that

vertexCoords : Array of vertex coordinates (x, y, z) to which to color

But if you cast the vertexCoords to float [3], you will get an error.

To work this round, we have to use the notion of pointer, which results in Unsafe code:

public int Value(object face, ref float vertexCoords, ref float normalCoords, out double Value)
{
float X, Y, Z;
X = vertexCoords;

unsafe
{
fixed (float* Pos = &vertexCoords)
{
Y = *(Pos + 1);
Z = *(Pos + 2);
}
}
}

Two noteworthy points:

  1. We have to wrap the unsafe code into an unsafe block; see this article for the unsafe usage.
  2. The fixed statement prevents the garbage collector from relocating a movable variable. The fixed statement is only permitted in an unsafe context. Fixed can also be used to create fixed size buffers. See also MSND here.

Finally, remember to change the project setting to allow unsafe code compiling.

Advertisements
 
Leave a comment

Posted by on July 14, 2008 in CAD, Dotnet/C#

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: