Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Mesh color
Forum Updated to NodeBB v4.3 + New Features

Mesh color

Scheduled Pinned Locked Moved Solved General and Desktop
23 Posts 5 Posters 11.8k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #9

    Got it to work but need to clean it up now. The faces are colored in typical FEM/CFD style in 10 steps. Could also use a continous color scale, doesn't make much difference in the code. Looks nice ^_^

    screenshot

    1 Reply Last reply
    4
    • F Offline
      F Offline
      Florent Mathieu
      wrote on last edited by Florent Mathieu
      #10

      @Wieland Looks nice indeed ! It's a classical FE look, pretty much what I'm looking for (except I like better the new matlab colormaps but this choice belongs to the user ;) ).

      ? 1 Reply Last reply
      0
      • F Florent Mathieu

        @Wieland Looks nice indeed ! It's a classical FE look, pretty much what I'm looking for (except I like better the new matlab colormaps but this choice belongs to the user ;) ).

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #11

        @Florent-Mathieu Hi! I've created a demo application. I've sent you a chat message with the download link. If you have any questions feel free to ask them here.

        F 1 Reply Last reply
        0
        • ? A Former User

          @Florent-Mathieu Hi! I've created a demo application. I've sent you a chat message with the download link. If you have any questions feel free to ask them here.

          F Offline
          F Offline
          Florent Mathieu
          wrote on last edited by Florent Mathieu
          #12

          @Wieland

          Hey, thanks for this, it seems amazing. However it seems maybe a version issue prevents me to compile. Indeed I have a few problems :

          • I don't have a "Qtrender" folder in the repositories, just "Qtrenderer". This can be modified easily, then come the real things
          • I don't have a Qt3DRender::QGeometry or Qt3DCore::QNode. All of these classes I can find in Qt3D (and not Qt3DRender or Qt3DCore).
          • This leads to probably a linking problem :
            /Users/LMT/Downloads/meshviewer/femmeshgeometry.cpp:15: erreur : initializer 'QGeometry' does not name a non-static data member or base class; did you mean the base class 'QGeometry'?
            : Qt3DRender::QGeometry(parent)
            ^~~~~~~~~
            QGeometry

          ... and further issues when I tried to replace all QtRender's by Qt3D which has the class. Do you have a hint on how to solve this ? Currently using 5.5, maybe I just need to update ?

          Thanks again !

          P 1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #13

            You need to update to Qt 5.6 (beta).

            F 1 Reply Last reply
            0
            • ? A Former User

              You need to update to Qt 5.6 (beta).

              F Offline
              F Offline
              Florent Mathieu
              wrote on last edited by
              #14

              @Wieland Hey, thanks for the info. Two questions then :

              • I obtain a gray 'A', no colors set from the beginning. How can I set them ?
              • I tried a few things which didn't work and prevented from compiling. Now a.off won't open :
              QFile::open: File (:assets/a.off) already open
              

              ... even if I restart Qt, change/replace the file. do you have any idea why ? I already checked it wasn't open in another program.

              Thanks again, and sorry for being slow :)

              ? 1 Reply Last reply
              0
              • F Florent Mathieu

                @Wieland Hey, thanks for the info. Two questions then :

                • I obtain a gray 'A', no colors set from the beginning. How can I set them ?
                • I tried a few things which didn't work and prevented from compiling. Now a.off won't open :
                QFile::open: File (:assets/a.off) already open
                

                ... even if I restart Qt, change/replace the file. do you have any idea why ? I already checked it wasn't open in another program.

                Thanks again, and sorry for being slow :)

                ? Offline
                ? Offline
                A Former User
                wrote on last edited by A Former User
                #15

                @Florent-Mathieu said:

                I obtain a gray 'A', no colors set from the beginning. How can I set them ?

                That's a problem with your graphics card driver. I developed the program on a Linux machine with a Nvidia graphics card and with original Nvidia driver installed. There the program works fine. I also tested the program on another machine that has only integrated Intel graphics and uses the Mesa driver and the program shows only a dark "A" on that machine. The example program from KDAB (the red trefoil knot with black mesh lines) doesn't work on that machine either. Generally speaking, the various free graphics cards drivers for Linux all have very incomplete OpenGl support so if your software really has to run on such computer you'll have to find out what OpenGl features are supported on that machine and then work around the missing parts.

                F 1 Reply Last reply
                1
                • ? A Former User

                  @Florent-Mathieu said:

                  I obtain a gray 'A', no colors set from the beginning. How can I set them ?

                  That's a problem with your graphics card driver. I developed the program on a Linux machine with a Nvidia graphics card and with original Nvidia driver installed. There the program works fine. I also tested the program on another machine that has only integrated Intel graphics and uses the Mesa driver and the program shows only a dark "A" on that machine. The example program from KDAB (the red trefoil knot with black mesh lines) doesn't work on that machine either. Generally speaking, the various free graphics cards drivers for Linux all have very incomplete OpenGl support so if your software really has to run on such computer you'll have to find out what OpenGl features are supported on that machine and then work around the missing parts.

                  F Offline
                  F Offline
                  Florent Mathieu
                  wrote on last edited by
                  #16

                  @Wieland Okay, I'll try on another computer. I currently use a macbook pro, on which the first example was running. Thanks for the heads up

                  F 1 Reply Last reply
                  0
                  • F Florent Mathieu

                    @Wieland Okay, I'll try on another computer. I currently use a macbook pro, on which the first example was running. Thanks for the heads up

                    F Offline
                    F Offline
                    Florent Mathieu
                    wrote on last edited by
                    #17

                    @Wieland Indeed it works now, but only after I updated the nvidia drivers to the latest version, good to know. Two last questions then before I close the topic :

                    • I cannot seem to understand where the color data is introduced in the material. Is the temperature what you plot ?
                    • I keep having this error when trying to move the scene:
                    Qt3D.Renderer.Backend: void Qt3DRender::Render::RenderView::setShaderAndUniforms(Qt3DRender::Render::RenderCommand*, Qt3DRender::Render::RenderPass*, Qt3DRender::Render::ParameterInfoList&, const QMatrix4x4&, const QVector<Qt3DRender::Render::RenderView::LightSource>&) Trying to bind a Parameter that hasn't been defined "vertexTemperature"
                    

                    Do you have this too ?

                    ? 2 Replies Last reply
                    0
                    • F Florent Mathieu

                      @Wieland Indeed it works now, but only after I updated the nvidia drivers to the latest version, good to know. Two last questions then before I close the topic :

                      • I cannot seem to understand where the color data is introduced in the material. Is the temperature what you plot ?
                      • I keep having this error when trying to move the scene:
                      Qt3D.Renderer.Backend: void Qt3DRender::Render::RenderView::setShaderAndUniforms(Qt3DRender::Render::RenderCommand*, Qt3DRender::Render::RenderPass*, Qt3DRender::Render::ParameterInfoList&, const QMatrix4x4&, const QVector<Qt3DRender::Render::RenderView::LightSource>&) Trying to bind a Parameter that hasn't been defined "vertexTemperature"
                      

                      Do you have this too ?

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by A Former User
                      #18

                      @Florent-Mathieu Glad to hear it works now :) This error.. I know it, it nearly drove me crazy but eventually I figured out where it comes from. In FemEffect.qml there is

                      , ParameterMapping { parameterName: "vertexPosition"; shaderVariableName: "vertexPosition"; bindingType: ParameterMapping.Attribute }
                      , ParameterMapping { parameterName: "vertexForce"; shaderVariableName: "vertexForce"; bindingType: ParameterMapping.Attribute }
                      , ParameterMapping { parameterName: "vertexTemperature"; shaderVariableName: "vertexTemperature"; bindingType: ParameterMapping.Attribute 
                      

                      These ParameterMapping s tell the render pipeline that we have attributes with the names "vertexPosition", "vertexForce" and "vertexTemperature". These are the attributes in femmeshgeometry.h :

                          Qt3DRender::QAttribute *m_positionAttribute;
                          Qt3DRender::QAttribute *m_forceAttribute;
                          Qt3DRender::QAttribute *m_temperatureAttribute;
                      

                      They get their actual names in femmeshgeometry.cpp:

                      // Qt3DRender::QAttribute::defaultPositionAttributeName() return "vertexPosition"
                      m_positionAttribute->setName(Qt3DRender::QAttribute::defaultPositionAttributeName());
                      ...
                      m_forceAttribute->setName("vertexForce");
                      ...
                      m_temperatureAttribute->setName("vertexTemperature");
                      

                      In FemEffect.qml the parameter mappings tell the render pipeline that these attributes are used in our vertex shader (fem.vert). "Attribute" is the OpenGl terminology for "input value for a vertex shader". So the mappings say: We have three input values for our vertex shader and the values in C++ have the names "vertexPosition", "vertexForce" and "vertexTemperature" and we use the same names in fem.vert.

                      When and why does the error arise? The error comes from the ParameterMapping when Qt3D tries to map our C++ attribute to an attribute in the vertex shader but the vertex shader does not contain an attribute with that name.

                      Now you ask: "But vertexTemperature is in the vertex shader! I can see it in the file right on top!" Here comes the magic: The shader is compiled by the graphics driver at runtime. It also does optimization. If the vertexTemperature attribute is not actually used then the shader compiler optimizes it away and the parameter mapping fails. This is what my comment in fem.vert is about:

                      / Beware to actually use the input in the code !
                      // Otherwise the shader compiler will optimize them away
                      // and then the Qt3D parameter bindings will scream error!
                      
                      1 Reply Last reply
                      1
                      • F Florent Mathieu

                        @Wieland Indeed it works now, but only after I updated the nvidia drivers to the latest version, good to know. Two last questions then before I close the topic :

                        • I cannot seem to understand where the color data is introduced in the material. Is the temperature what you plot ?
                        • I keep having this error when trying to move the scene:
                        Qt3D.Renderer.Backend: void Qt3DRender::Render::RenderView::setShaderAndUniforms(Qt3DRender::Render::RenderCommand*, Qt3DRender::Render::RenderPass*, Qt3DRender::Render::ParameterInfoList&, const QMatrix4x4&, const QVector<Qt3DRender::Render::RenderView::LightSource>&) Trying to bind a Parameter that hasn't been defined "vertexTemperature"
                        

                        Do you have this too ?

                        ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by A Former User
                        #19

                        @Florent-Mathieu said:

                        I cannot seem to understand where the color data is introduced in the material. Is the temperature what you plot ?

                        The color is computed in the fragment shader (fem.frag):

                        vec4 shadeLine( const in vec4 color )
                        {
                        ...
                        vec4 ccc = vec4( computeRed(color.r), computeGreen(color.r), computeBlue(color.r), 1.0 );
                        ...
                        }
                        
                        void main()
                        {
                            vec4 color = vec4(fs_in.force, 1.0);   
                            fragColor = shadeLine( color  );
                        }
                        

                        In the demo I use the force value to compute a color from it. More specifically I only use the x component (color.r).

                        The values for vertexForce and vertexTemperature are not contained in the a.off file. I assign random force and temperature data at runtime when the a.off file is loaded. You can find the code in meshdataloaderoff.cpp:

                        static bool readVertexData(QTextStream &in, QVector3D &position, QVector3D &force, float &temperature)
                        {
                            const QStringList lst = readSkip(in).split(' ');
                            if (lst.size()<3) return false; // TODO: 7
                            int idx = 0;
                            bool ok = false;
                            position.setX( lst.at(idx++).toFloat(&ok) ); if (!ok) return false;
                            position.setY( lst.at(idx++).toFloat(&ok) ); if (!ok) return false;
                            position.setZ( lst.at(idx++).toFloat(&ok) ); if (!ok) return false;
                        
                            // TODO: remove comments
                            //    force.setX( lst.at(idx++).toFloat(&ok) ); if (!ok) return false;
                            //    force.setY( lst.at(idx++).toFloat(&ok) ); if (!ok) return false;
                            //    force.setZ( lst.at(idx++).toFloat(&ok) ); if (!ok) return false;
                            //    temperature = lst.at(idx++).toFloat(&ok); if (!ok) return false;
                        
                            // TODO: remove this
                            force.setX( randomFloat() );
                            force.setY( randomFloat() );
                            force.setZ( randomFloat() );
                            temperature = randomFloat();
                        
                            return true;
                        }
                        

                        I did this because I had this a.off file at hand and it contained only geometric data. You can add additional float values to the vertices in the off file and change the code above to use these values.

                        1 Reply Last reply
                        0
                        • F Offline
                          F Offline
                          Florent Mathieu
                          wrote on last edited by
                          #20

                          @Wieland Can't see how I missed that. Thanks a lot, that's great, I'm going to close the topic.

                          1 Reply Last reply
                          0
                          • ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by
                            #21

                            The reason I introduced force and temperature data in the demo is because I wanted to show how to push vector and scalar data into the vertex shader. Clearly this was hard enough to figure out as Qt3D has no documentation yet and I had to learn everything from the sources ;-)

                            1 Reply Last reply
                            1
                            • F Florent Mathieu

                              @Wieland

                              Hey, thanks for this, it seems amazing. However it seems maybe a version issue prevents me to compile. Indeed I have a few problems :

                              • I don't have a "Qtrender" folder in the repositories, just "Qtrenderer". This can be modified easily, then come the real things
                              • I don't have a Qt3DRender::QGeometry or Qt3DCore::QNode. All of these classes I can find in Qt3D (and not Qt3DRender or Qt3DCore).
                              • This leads to probably a linking problem :
                                /Users/LMT/Downloads/meshviewer/femmeshgeometry.cpp:15: erreur : initializer 'QGeometry' does not name a non-static data member or base class; did you mean the base class 'QGeometry'?
                                : Qt3DRender::QGeometry(parent)
                                ^~~~~~~~~
                                QGeometry

                              ... and further issues when I tried to replace all QtRender's by Qt3D which has the class. Do you have a hint on how to solve this ? Currently using 5.5, maybe I just need to update ?

                              Thanks again !

                              P Offline
                              P Offline
                              PshyX
                              wrote on last edited by
                              #22

                              @Florent-Mathieu can i get the demo application ?

                              1 Reply Last reply
                              0
                              • F Offline
                                F Offline
                                Florent Mathieu
                                wrote on last edited by
                                #23

                                Hi! I'm sorry I don't have it any more. We switched to VTK for 3D interface because it seemed more mature at the time. In any case it probably evolved in Qt3D as well so I think it would not be up to date.

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved