/// <summary>
        /// Returns a mapping tag that is used to detect when
        /// a meshes colors need to be set.  For details, see the
        /// implementation  of MappingTag and UpdateVertexColors.
        /// </summary>
        /// <returns></returns>
        public OnMappingTag MappingTag()
        {
            OnMappingTag mt = new OnMappingTag();

              // Since the false colors that are shown will change if
              // the mesh is transformed, we have to initialize the
              // transformation.
              mt.m_mesh_xform.Identity();

              // This is the analysis mode id passed to the
              // CRhinoVisualAnalysisMode constructor. Use the
              // m_am_id member and it this code will alwasy
              // work correctly.
              mt.m_mapping_id = m_am_id;

              // This is a 32 bit CRC or the information used to
              // set the false colors.
              // For this example, the m_z_range and m_hue_range
              // intervals control the colors, so we calculate
              // their crc.
              mt.m_mapping_crc = 0;
              mt.m_mapping_crc = Crc32.ComputeChecksum(m_z_range);
              mt.m_mapping_crc = Crc32.ComputeChecksum(m_hue_range);
              return mt;
        }
Exemple #2
0
        /// <summary>
        /// Returns a mapping tag that is used to detect when
        /// a meshes colors need to be set.  For details, see the
        /// implementation  of MappingTag and UpdateVertexColors.
        /// </summary>
        /// <returns></returns>
        public OnMappingTag MappingTag()
        {
            OnMappingTag mt = new OnMappingTag();

            // Since the false colors that are shown will change if
            // the mesh is transformed, we have to initialize the
            // transformation.
            mt.m_mesh_xform.Identity();

            // This is the analysis mode id passed to the
            // CRhinoVisualAnalysisMode constructor. Use the
            // m_am_id member and it this code will alwasy
            // work correctly.
            mt.m_mapping_id = m_am_id;

            // This is a 32 bit CRC or the information used to
            // set the false colors.
            // For this example, the m_z_range and m_hue_range
            // intervals control the colors, so we calculate
            // their crc.
            mt.m_mapping_crc = 0;
            mt.m_mapping_crc = Crc32.ComputeChecksum(m_z_range);
            mt.m_mapping_crc = Crc32.ComputeChecksum(m_hue_range);
            return(mt);
        }
Exemple #3
0
        /// <summary>
        /// MRhinoVisualAnalysisMode override
        /// </summary>
        public override void UpdateVertexColors(IRhinoObject obj, OnMesh[] meshes)
        {
            // Rhino calls this function when it is time for you
            // to set the false colors on the analysis mesh vertices.
            // For breps, there is one mesh per face.  For mesh objects,
            // there is a single mesh.
            int count = meshes.Length;

            if (count > 0)
            {
                // A "mapping tag" is used to determine if the colors need to be set
                OnMappingTag mt = MappingTag();
                for (int mi = 0; mi < count; mi++)
                {
                    OnMesh mesh = meshes[mi];
                    if (null != mesh && 0 != mt.Compare(mesh.m_Ctag))
                    {
                        // The mesh's mapping tag is different from ours. Either
                        // the mesh has no false colors, has false colors set by
                        // another analysis mode, has false colors set using
                        // different m_z_range[]/m_hue_range[] values, or the
                        // mesh has been moved.  In any case, we need to set
                        // the false colors to the ones we want.
                        int          vcount        = mesh.m_V.Count();
                        ArrayOnColor vertex_colors = mesh.m_C;
                        vertex_colors.SetCount(0);     // in case something else had set the colors
                        vertex_colors.Reserve(vcount); // for efficiency
                        for (int vi = 0; vi < vcount; vi++)
                        {
                            double  z     = mesh.m_V[vi].z;
                            OnColor color = FalseColor(z);
                            vertex_colors.Append(color);
                        }

                        // set the mesh's color tag
                        mesh.m_Ctag = mt;
                    }
                }
            }
        }