Announcement

Collapse
No announcement yet.

How to draw many (about millions) rectangles with different colors?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to draw many (about millions) rectangles with different colors?

    Dear openInentor programmers,
    How to draw many (about millions) rectangles with different colors? and they are showed like attchments.
    I use SoIndexedFaced,and find that it is not easy to realize it? Could you tell me how to realize ?
    Thank you very much.
    Attached Files

  • #2
    Hi,
    I can give you some general advice on this topic. Also some specific advice (eventually), but I am not sure what part of this task is causing difficulty.

    The most convenient nodes to use for rectangles (quads) are:
    • SoFaceSet : if rectangles do not share vertices.
    • SoIndexedFaceSet : if rectangles DO share vertices
    One other option is SoBufferedShape, which can be more efficient for large geometry, but is more complicated to use. It's usually best to start with one of the FaceSet nodes and get the right rendering before trying to use BufferedShape.

    Here are the general steps for using SoIndexedFaceSet. I'll use C++, but it's similar in .NET or Java.
    Create the geometry:
    1. Create an SoVertexProperty node.
    2. Set the coordinates in the 'vertex' field of the SoVertexProperty node.
      Note: If your coordinates are already stored in a float array as X, Y, Z, X, Y, Z, ... you can set them without copying the data. See SoMFVec3f::setValuesPointer().
    3. Create an SoIndexedFaceSet node.
    4. Set the VertexProperty node in the 'vertex' field of the IndexedFaceSet.
    5. Set the coordinate indices in the 'coordIndex' field of the IndexedFaceSet.
      • For each rectangle you need 5 values: 4 indices plus a "-1" value to mark the end of the face.
        For example: 0, 1, 2, 3, -1, 2, 3, 4, 5, -1, ...
      • Just like vertices, if you already have coordinate indices in an int array, you can set them without copying the data.
      • After adding the IndexedFaceSet to your scene graph, you should be able to see the shape rendered (without color).
    Set a color for each rectangle:
    • First, you need to tell the IndexedFaceSet that the colors are "per-face".
    • Second, you need to store the color values in the scene graph.
    There are two ways to do that:
    1. Using the SoVertexProperty node.
      This is the most efficient way, because packed RGBA values can be sent directly to the GPU.
      Using the VertexProperty node you created:
      • Set the 'materialBinding' field to PER_FACE.
      • In the 'orderedRGBA' field, set N color values, where N is the number of rectangles.
        Each RGBA value is a 32-bit, unsigned int.
        Using the SbColor class, the R, G, and B values are float in the range 0..1.
        You can convert the color value to packed RGBA using the method SbColor::getPackedValue().

        or
    2. Using SoMaterialBinding and SoMaterial nodes
      ​​​​​​​This is more convenient and Open Inventor will convert the color values to RGBA internally.
      • Create an SoMaterialBinding node and set the 'value' field to PER_FACE.
      • Create an SoMatieral node and set N values in the 'diffuseColor' field, where N is the number of rectangles.
      • Add both nodes to the scene graph before the IndexedFaceSet node.
    Let us know if you have more questions.
    Regards,
    ​​​​​​​Mike

    Comment


    • #3
      Thank you VERYV

      Comment


      • #4
        Thank you VERY VERY much for your answer!
        I realize it as you said.
        And now I want to draw picture with some holes,and find 'SoShapeHints' can define geometry containing holes,and WindingType can be 'ODD_TYPE,NON_ZERO_TYPE...',.I have two questions.
        • Is the winding number of regions assigned automatically by OpenInventor,If it is, How does the WindingType ‘ODD_TYPE,NON_ZERO_TYPE...’ define holes irregularly because the location of the holes in my geometry is not regular,
        • If the value of the winding number of regions can be assigned by programmer,could you tell me how to do ?
        Thank you,Mike.
        Last edited by Mike_new; January 23, 2021, 01:17 AM.

        Comment


        • #5
          Originally posted by Mike_new View Post
          Is the winding number of regions assigned automatically by OpenInventor,If it is, How does the WindingType ‘ODD_TYPE,NON_ZERO_TYPE...’ define holes irregularly because the location of the holes in my geometry is not regular,
          Hi,
          Yes, the winding number of a region is computed automatically.
          There is an explanation in the online user guide here (scroll down to the section "Polygons with holes").
          Regards,
          Mike

          Comment


          • #6
            I explain my process of implementing a rule area without holes (core codes)

            1) This area is rectangular (M rows, n columns);
            2) Use sovertexproperty to create the point coordinates and the rendering colors of each point
            ...
            SoVertexProperty *property = new SoVertexProperty;
            property->materialBinding =SoMaterialBingding::PER_ VERTEX_ INDEXED;
            property-> vertex.setNum (m*n);
            SbbVec3f *pVert = property-> vertex.startEditing ();
            for(int i=0;i<m;i++)
            for(int j = 0;j<n;j++)
            {
            pVert->setValue(x[i*m+j],y[i*m+j],z[i*m+j]);
            pVert++;
            }
            property-> vertex.finishEditing ();

            3) Soindexedfaceset is used to create the index of each node

            ...
            SoIndexedFaceSet *indexSet=new SoIndexedFaceSet;
            indexSet-> coordIndex.setNum (m*n*5);
            int* pIndex = indexSet-> coordIndex.startEditing ();

            for(int i=0;i<m-1;i++)
            for(int j =0;j<n-1;j++)
            {
            *pIndex++ =i*m+j;
            *pIndex++ =i*m+j+1;
            *pIndex++ =(i+1)*m+j+1;
            *pIndex++ =(i+1)*m+j;
            *pIndex++=-1;
            }

            indexSet-> coordIndex.finishEditing ();
            indexSet->vertexProperty = property;


            The above codes are about the display of rectangles without holes.
            The positions of holes in rectangles are random, as shown in the attachment. Could you tell me how to define I don't know how to Soindexedfaceset?

            Regards
            Mike_new
            Last edited by Mike_new; January 29, 2021, 10:06 PM.

            Comment


            • #7
              this is picture with holes I will draw.Thank you.
              Attached Files

              Comment


              • #8
                Originally posted by Mike_new View Post
                this is picture with holes I will draw.
                Sorry, but I don't see the picture or any attachment. It's possible you have encountered a limitation of the Forum (file type, file size, etc).
                I sent a link in a private message that you can use to upload the attachment.
                Regards,
                Mike

                Comment


                • #9
                  Thank you, Mike, I have sent the picture to you.

                  Comment


                  • #10
                    Originally posted by Mike_new View Post
                    Thank you, Mike, I have sent the picture to you.
                    Received and added below.
                    This looks like a horizon surface with some undefined values. You should consider rendering it using SoHeightFieldGeometry and SoHeightFieldRender. It will use less memory and have better performance, but most importantly SoHeightFieldGeometry allows you to specify an undefined value. Rectangles touching an undefined vertex will not be drawn.
                    Regards,
                    Mike

                    withHoles.png

                    Comment


                    • #11
                      Thank you,Mike. I will try.

                      Comment


                      • #12
                        Dear Mike,Could you tell me how to convert horizon data(x,y,z) to LDM data?The example only show how to display ldm file with SoHeightFieldGeometry.
                        Last edited by Mike_new; February 3, 2021, 07:29 PM.

                        Comment

                        Working...
                        X