From 59ee34efc0932673111fff7f46b9f573bb7a44c5 Mon Sep 17 00:00:00 2001 From: kgv Date: Fri, 30 Aug 2019 17:54:09 +0300 Subject: [PATCH] 0030930: Draw Harness, ViewerTest - add commands vlistcolors and vlistmaterials listing standard Colors and Materials Introduced two new commands vlistcolors listing named colors and vlistmaterials listing standard materials. These commands also can generate HTML table listing colors/materials with their properties. vlistmaterials can generate OBJ model for comparing OCCT materials in different viewers. New test cases use these commands for generating HTML tables. Graphic3d_MaterialAspect::MaterialType() - added missing getter. Corrected name of unlit shading model within vaspects and vrenderparams commands. --- src/Graphic3d/Graphic3d_MaterialAspect.hxx | 3 + src/Graphic3d/Graphic3d_TypeOfMaterial.hxx | 4 +- src/Quantity/Quantity_Color.hxx | 26 +- src/Quantity/Quantity_NameOfColor.hxx | 3 +- src/ViewerTest/ViewerTest.cxx | 6 +- src/ViewerTest/ViewerTest_OpenGlCommands.cxx | 484 +++++++++++++++++++ src/ViewerTest/ViewerTest_ViewerCommands.cxx | 2 +- tests/v3d/materials/colors | 32 ++ tests/v3d/materials/materials | 21 + 9 files changed, 565 insertions(+), 16 deletions(-) create mode 100644 tests/v3d/materials/colors create mode 100644 tests/v3d/materials/materials diff --git a/src/Graphic3d/Graphic3d_MaterialAspect.hxx b/src/Graphic3d/Graphic3d_MaterialAspect.hxx index 9d4ee83e52..78b9b1045e 100644 --- a/src/Graphic3d/Graphic3d_MaterialAspect.hxx +++ b/src/Graphic3d/Graphic3d_MaterialAspect.hxx @@ -208,6 +208,9 @@ public: //! Deactivates the reflective properties of the surface with specified reflection type. void SetReflectionModeOff (const Graphic3d_TypeOfReflection theType) { SetReflectionMode (theType, Standard_False); } + //! Returns material type. + Graphic3d_TypeOfMaterial MaterialType() const { return myMaterialType; } + //! Returns TRUE if type of this material is equal to specified type. Standard_Boolean MaterialType (const Graphic3d_TypeOfMaterial theType) const { return myMaterialType == theType; } diff --git a/src/Graphic3d/Graphic3d_TypeOfMaterial.hxx b/src/Graphic3d/Graphic3d_TypeOfMaterial.hxx index d8ee5e96eb..4f1590416a 100644 --- a/src/Graphic3d/Graphic3d_TypeOfMaterial.hxx +++ b/src/Graphic3d/Graphic3d_TypeOfMaterial.hxx @@ -20,8 +20,8 @@ //! Types of materials specifies if a material can change color. enum Graphic3d_TypeOfMaterial { -Graphic3d_MATERIAL_ASPECT, -Graphic3d_MATERIAL_PHYSIC + Graphic3d_MATERIAL_ASPECT, //!< aspect material definition with configurable color (like plastic) + Graphic3d_MATERIAL_PHYSIC //!< physical material definition with fixed color (like gold) }; #endif // _Graphic3d_TypeOfMaterial_HeaderFile diff --git a/src/Quantity/Quantity_Color.hxx b/src/Quantity/Quantity_Color.hxx index 07ce584ec6..77fbf22f82 100644 --- a/src/Quantity/Quantity_Color.hxx +++ b/src/Quantity/Quantity_Color.hxx @@ -19,14 +19,11 @@ #include #include #include - #include + #include #include -#include -#include -#include -#include +#include #include class Quantity_ColorDefinitionError; @@ -51,11 +48,10 @@ public: DEFINE_STANDARD_ALLOC - //! Creates a colour with the default value of - //! Colour name : YELLOW + //! Creates Quantity_NOC_YELLOW color. Standard_EXPORT Quantity_Color(); - //! Creates the colour . + //! Creates the color from enumeration value. Standard_EXPORT Quantity_Color(const Quantity_NameOfColor AName); //! Creates a color according to the definition system theType. @@ -98,12 +94,12 @@ public: Standard_EXPORT void SetValues (const Quantity_NameOfColor AName); //! Updates a color according to the mode specified by theType. - //! TOC_RGB: + //! Quantity_TOC_RGB: //! - theR1 the value of Red within range [0.0; 1.0] //! - theR2 the value of Green within range [0.0; 1.0] //! - theR3 the value of Blue within range [0.0; 1.0] //! - //! TOC_HLS: + //! Quantity_TOC_HLS: //! - theR1 is the Hue (H) angle in degrees within range [0.0; 360.0], 0.0 being Red. //! -1.0 is a special value reserved for grayscale color (S should be 0.0). //! - theR2 is the Lightness (L) within range [0.0; 1.0] @@ -247,6 +243,16 @@ Standard_Boolean operator == (const Quantity_Color& Other) const //! @return true if parsing was successful, or false otherwise Standard_EXPORT static bool ColorFromHex (const Standard_CString theHexColorString, Quantity_Color& theColor); + //! Returns hex sRGB string in format "#FFAAFF". + static TCollection_AsciiString ColorToHex (const Quantity_Color& theColor) + { + NCollection_Vec3 anSRgb = (NCollection_Vec3 )theColor; + NCollection_Vec3 anSRgbInt (anSRgb * 255.0f); + char aBuff[10]; + Sprintf (aBuff, "#%02X%02X%02X", anSRgbInt.r(), anSRgbInt.g(), anSRgbInt.b()); + return aBuff; + } + //! Converts HLS components into RGB ones. Standard_EXPORT static void HlsRgb (const Standard_Real H, const Standard_Real L, const Standard_Real S, Standard_Real& R, Standard_Real& G, Standard_Real& B); diff --git a/src/Quantity/Quantity_NameOfColor.hxx b/src/Quantity/Quantity_NameOfColor.hxx index 34f885a456..1ef519b274 100644 --- a/src/Quantity/Quantity_NameOfColor.hxx +++ b/src/Quantity/Quantity_NameOfColor.hxx @@ -17,7 +17,8 @@ #ifndef _Quantity_NameOfColor_HeaderFile #define _Quantity_NameOfColor_HeaderFile -//! Definition of names of known colours. +//! Definition of names of known colors. +//! The names come (mostly) from the X11 specification. enum Quantity_NameOfColor { Quantity_NOC_BLACK, diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index 100d63efda..d008ef9a01 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -6608,7 +6608,7 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands) "\n\t\t: [-isoontriangulation 0|1]" "\n\t\t: [-setMaxParamValue {value}]" "\n\t\t: [-setSensitivity {selection_mode} {value}]" - "\n\t\t: [-setShadingModel {color|flat|gouraud|phong}]" + "\n\t\t: [-setShadingModel {unlit|flat|gouraud|phong}]" "\n\t\t: [-unsetShadingModel]" "\n\t\t: [-setInterior {solid|hatch|hidenline|point}]" "\n\t\t: [-unsetInterior] [-setHatch HatchStyle]" @@ -6623,7 +6623,9 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands) "\n\t\t: When -defaults is specified than presentation properties will be" "\n\t\t: assigned to all objects that have not their own specified properties" "\n\t\t: and to all objects to be displayed in the future." - "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.", + "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier." + "\n\t\t: See also vlistcolors and vlistmaterials to list named colors and materials" + "\n\t\t: accepted by arguments -setMaterial and -setColor", __FILE__,VAspects,group); theCommands.Add("vsetcolor", diff --git a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx index dc5feb247d..b6d41ec969 100644 --- a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx +++ b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,7 @@ #include #include #include +#include extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, const Handle(AIS_InteractiveObject)& theAISObj, @@ -873,6 +875,474 @@ static Standard_Integer VShaderProg (Draw_Interpretor& theDI, return 0; } +//! Print triplet of values. +template static S& operator<< (S& theStream, const NCollection_Vec3& theVec) +{ + theStream << theVec[0] << " " << theVec[1] << " " << theVec[2]; + return theStream; +} + +//! Print 4 values. +template static S& operator<< (S& theStream, const NCollection_Vec4& theVec) +{ + theStream << theVec[0] << " " << theVec[1] << " " << theVec[2] << " " << theVec[3]; + return theStream; +} + +//! Print fresnel model. +static const char* fresnelModelString (const Graphic3d_FresnelModel theModel) +{ + switch (theModel) + { + case Graphic3d_FM_SCHLICK: return "SCHLICK"; + case Graphic3d_FM_CONSTANT: return "CONSTANT"; + case Graphic3d_FM_CONDUCTOR: return "CONDUCTOR"; + case Graphic3d_FM_DIELECTRIC: return "DIELECTRIC"; + } + return "N/A"; +} + +//! Create a colored rectangle SVG element. +static TCollection_AsciiString formatSvgColoredRect (const Quantity_Color& theColor) +{ + return TCollection_AsciiString() + + ""; +} + +//============================================================================== +//function : VListMaterials +//purpose : +//============================================================================== +static Standard_Integer VListMaterials (Draw_Interpretor& theDI, + Standard_Integer theArgNb, + const char** theArgVec) +{ + TCollection_AsciiString aDumpFile; + NCollection_Sequence aMatList; + for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) + { + TCollection_AsciiString anArg (theArgVec[anArgIter]); + anArg.LowerCase(); + Graphic3d_NameOfMaterial aMat = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter]); + if (aMat != Graphic3d_NOM_DEFAULT) + { + aMatList.Append (aMat); + } + else if (anArg == "*") + { + for (Standard_Integer aMatIter = 0; aMatIter < (Standard_Integer )Graphic3d_NOM_DEFAULT; ++aMatIter) + { + aMatList.Append ((Graphic3d_NameOfMaterial )aMatIter); + } + } + else if (aDumpFile.IsEmpty() + && (anArg.EndsWith (".obj") + || anArg.EndsWith (".mtl") + || anArg.EndsWith (".htm") + || anArg.EndsWith (".html"))) + { + aDumpFile = theArgVec[anArgIter]; + } + else + { + std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'\n"; + return 1; + } + } + if (aMatList.IsEmpty()) + { + if (aDumpFile.IsEmpty()) + { + for (Standard_Integer aMatIter = 1; aMatIter <= Graphic3d_MaterialAspect::NumberOfMaterials(); ++aMatIter) + { + theDI << Graphic3d_MaterialAspect::MaterialName (aMatIter) << " "; + } + return 0; + } + + for (Standard_Integer aMatIter = 0; aMatIter < (Standard_Integer )Graphic3d_NOM_DEFAULT; ++aMatIter) + { + aMatList.Append ((Graphic3d_NameOfMaterial )aMatIter); + } + } + + // geometry for dumping + const Graphic3d_Vec3 aBoxVerts[8] = + { + Graphic3d_Vec3( 1, -1, -1), + Graphic3d_Vec3( 1, -1, 1), + Graphic3d_Vec3(-1, -1, 1), + Graphic3d_Vec3(-1, -1, -1), + Graphic3d_Vec3( 1, 1, -1), + Graphic3d_Vec3( 1, 1, 1), + Graphic3d_Vec3(-1, 1, 1), + Graphic3d_Vec3(-1, 1, -1) + }; + + const Graphic3d_Vec4i aBoxQuads[6] = + { + Graphic3d_Vec4i (1, 2, 3, 4), + Graphic3d_Vec4i (5, 8, 7, 6), + Graphic3d_Vec4i (1, 5, 6, 2), + Graphic3d_Vec4i (2, 6, 7, 3), + Graphic3d_Vec4i (3, 7, 8, 4), + Graphic3d_Vec4i (5, 1, 4, 8) + }; + + std::ofstream aMatFile, anObjFile, anHtmlFile; + if (aDumpFile.EndsWith (".obj") + || aDumpFile.EndsWith (".mtl")) + { + const TCollection_AsciiString aMatFilePath = aDumpFile.SubString (1, aDumpFile.Length() - 3) + "mtl"; + const TCollection_AsciiString anObjFilePath = aDumpFile.SubString (1, aDumpFile.Length() - 3) + "obj"; + + OSD_OpenStream (aMatFile, aMatFilePath.ToCString(), std::ios::out | std::ios::binary); + if (!aMatFile.is_open()) + { + std::cout << "Error: unable creating material file\n"; + return 0; + } + if (!aDumpFile.EndsWith (".mtl")) + { + OSD_OpenStream (anObjFile, anObjFilePath.ToCString(), std::ios::out | std::ios::binary); + if (!anObjFile.is_open()) + { + std::cout << "Error: unable creating OBJ file\n"; + return 0; + } + + TCollection_AsciiString anMtlName, aFolder; + OSD_Path::FolderAndFileFromPath (aMatFilePath, aFolder, anMtlName); + anObjFile << "mtllib " << anMtlName << "\n"; + } + } + else if (aDumpFile.EndsWith (".htm") + || aDumpFile.EndsWith (".html")) + { + OSD_OpenStream (anHtmlFile, aDumpFile.ToCString(), std::ios::out | std::ios::binary); + if (!anHtmlFile.is_open()) + { + std::cout << "Error: unable creating HTML file\n"; + return 0; + } + anHtmlFile << "\n" + "OCCT Material table\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n"; + } + else if (!aDumpFile.IsEmpty()) + { + std::cout << "Syntax error: unknown output file format\n"; + return 1; + } + + Standard_Integer aMatIndex = 0, anX = 0, anY = 0; + for (NCollection_Sequence::Iterator aMatIter (aMatList); aMatIter.More(); aMatIter.Next(), ++aMatIndex) + { + Graphic3d_MaterialAspect aMat (aMatIter.Value()); + const TCollection_AsciiString aMatName = aMat.StringName(); + const Graphic3d_Vec3 anAmbient = aMat.ReflectionMode (Graphic3d_TOR_AMBIENT) + ? (Graphic3d_Vec3 )aMat.AmbientColor() * aMat.Ambient() + : Graphic3d_Vec3 (0.0f); + const Graphic3d_Vec3 aDiffuse = aMat.ReflectionMode (Graphic3d_TOR_DIFFUSE) + ? (Graphic3d_Vec3 )aMat.DiffuseColor() * aMat.Diffuse() + : Graphic3d_Vec3 (0.0f); + const Graphic3d_Vec3 aSpecular = aMat.ReflectionMode (Graphic3d_TOR_SPECULAR) + ? (Graphic3d_Vec3 )aMat.SpecularColor() * aMat.Specular() + : Graphic3d_Vec3 (0.0f); + const Graphic3d_Vec3 anEmission = aMat.ReflectionMode (Graphic3d_TOR_EMISSION) + ? (Graphic3d_Vec3 )aMat.EmissiveColor() * aMat.Emissive() + : Graphic3d_Vec3 (0.0f); + const Standard_Real aShiness = aMat.Shininess() * 1000.0; + if (aMatFile.is_open()) + { + aMatFile << "newmtl " << aMatName << "\n"; + aMatFile << "Ka " << anAmbient << "\n"; + aMatFile << "Kd " << aDiffuse << "\n"; + aMatFile << "Ks " << aSpecular << "\n"; + aMatFile << "Ns " << aShiness << "\n"; + if (aMat.Transparency() >= 0.0001) + { + aMatFile << "Tr " << aMat.Transparency() << "\n"; + } + aMatFile << "\n"; + } + else if (anHtmlFile.is_open()) + { + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + } + else + { + theDI << aMat.StringName() << "\n"; + theDI << " Common.Ambient: " << anAmbient << "\n"; + theDI << " Common.Diffuse: " << aDiffuse << "\n"; + theDI << " Common.Specular: " << aSpecular << "\n"; + theDI << " Common.Emissive: " << anEmission << "\n"; + theDI << " Common.Shiness: " << aMat.Shininess() << "\n"; + theDI << " Common.Transparency: " << aMat.Transparency() << "\n"; + theDI << " RefractionIndex: " << aMat.RefractionIndex() << "\n"; + theDI << " BSDF.Kc: " << aMat.BSDF().Kc << "\n"; + theDI << " BSDF.Kd: " << aMat.BSDF().Kd << "\n"; + theDI << " BSDF.Ks: " << aMat.BSDF().Ks << "\n"; + theDI << " BSDF.Kt: " << aMat.BSDF().Kt << "\n"; + theDI << " BSDF.Le: " << aMat.BSDF().Le << "\n"; + theDI << " BSDF.Absorption: " << aMat.BSDF().Absorption << "\n"; + theDI << " BSDF.FresnelCoat: " << fresnelModelString (aMat.BSDF().FresnelCoat.FresnelType()) << "\n"; + theDI << " BSDF.FresnelBase: " << fresnelModelString (aMat.BSDF().FresnelBase.FresnelType()) << "\n"; + } + + if (anObjFile.is_open()) + { + anObjFile << "g " << aMatName << "\n"; + anObjFile << "usemtl " << aMatName << "\n"; + for (Standard_Integer aVertIter = 0; aVertIter < 8; ++aVertIter) + { + anObjFile << "v " << (aBoxVerts[aVertIter] + Graphic3d_Vec3 (3.0f * anX, -3.0f * anY, 0.0f)) << "\n"; + } + anObjFile << "s off\n"; + for (Standard_Integer aFaceIter = 0; aFaceIter < 6; ++aFaceIter) + { + anObjFile << "f " << (aBoxQuads[aFaceIter] + Graphic3d_Vec4i (8 * aMatIndex)) << "\n"; + } + anObjFile << "\n"; + if (++anX > 5) + { + anX = 0; + ++anY; + } + } + } + + if (anHtmlFile.is_open()) + { + anHtmlFile << "
" + "Name
" + "Type
" + "Common
TransparencyRefraction Index
" + "BSDF
AmbientDiffuseSpecularEmissiveShiness
" + "Kc
" + "Kd
" + "Ks
" + "Kt
" + "Le
" + "Absorption
" + "FresnelCoat
" + "FresnelBase
" << aMat.StringName() << "" << (aMat.MaterialType() == Graphic3d_MATERIAL_PHYSIC ? "PHYSIC" : "ASPECT") << "" << formatSvgColoredRect (Quantity_Color (anAmbient)) << anAmbient << "" << formatSvgColoredRect (Quantity_Color (aDiffuse)) << aDiffuse << "" << formatSvgColoredRect (Quantity_Color (aSpecular)) << aSpecular << "" << formatSvgColoredRect (Quantity_Color (anEmission)) << anEmission << "" << aMat.Shininess() << "" << aMat.Transparency() << "" << aMat.RefractionIndex() << "" << aMat.BSDF().Kc << "" << aMat.BSDF().Kd << "" << aMat.BSDF().Ks << "" << aMat.BSDF().Kt << "" << aMat.BSDF().Le << "" << aMat.BSDF().Absorption << "" << fresnelModelString (aMat.BSDF().FresnelCoat.FresnelType()) << "" << fresnelModelString (aMat.BSDF().FresnelBase.FresnelType()) << "
\n\n\n"; + } + return 0; +} + +//============================================================================== +//function : VListColors +//purpose : +//============================================================================== +static Standard_Integer VListColors (Draw_Interpretor& theDI, + Standard_Integer theArgNb, + const char** theArgVec) +{ + TCollection_AsciiString aDumpFile; + NCollection_Sequence aColList; + for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) + { + TCollection_AsciiString anArg (theArgVec[anArgIter]); + anArg.LowerCase(); + Quantity_NameOfColor aName; + if (Quantity_Color::ColorFromName (theArgVec[anArgIter], aName)) + { + aColList.Append (aName); + } + else if (anArg == "*") + { + for (Standard_Integer aColIter = 0; aColIter <= (Standard_Integer )Quantity_NOC_WHITE; ++aColIter) + { + aColList.Append ((Quantity_NameOfColor )aColIter); + } + } + else if (aDumpFile.IsEmpty() + && (anArg.EndsWith (".htm") + || anArg.EndsWith (".html"))) + { + aDumpFile = theArgVec[anArgIter]; + } + else + { + std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'\n"; + return 1; + } + } + if (aColList.IsEmpty()) + { + if (aDumpFile.IsEmpty()) + { + for (Standard_Integer aColIter = 0; aColIter <= (Standard_Integer )Quantity_NOC_WHITE; ++aColIter) + { + theDI << Quantity_Color::StringName (Quantity_NameOfColor (aColIter)) << " "; + } + return 0; + } + + for (Standard_Integer aColIter = 0; aColIter <= (Standard_Integer )Quantity_NOC_WHITE; ++aColIter) + { + aColList.Append ((Quantity_NameOfColor )aColIter); + } + } + + std::ofstream anHtmlFile; + TCollection_AsciiString aFileNameBase, aFolder; + if (aDumpFile.EndsWith (".htm") + || aDumpFile.EndsWith (".html")) + { + OSD_Path::FolderAndFileFromPath (aDumpFile, aFolder, aFileNameBase); + aFileNameBase = aFileNameBase.SubString (1, aFileNameBase.Length() - (aDumpFile.EndsWith (".htm") ? 4 : 5)); + } + else if (!aDumpFile.IsEmpty()) + { + std::cout << "Syntax error: unknown output file format\n"; + return 1; + } + + Standard_Integer aMaxNameLen = 1; + for (NCollection_Sequence::Iterator aColIter (aColList); aColIter.More(); aColIter.Next()) + { + aMaxNameLen = Max (aMaxNameLen, TCollection_AsciiString (Quantity_Color::StringName (aColIter.Value())).Length()); + } + + V3d_ImageDumpOptions anImgParams; + anImgParams.Width = 60; + anImgParams.Height = 30; + anImgParams.BufferType = Graphic3d_BT_RGB; + anImgParams.StereoOptions = V3d_SDO_MONO; + anImgParams.ToAdjustAspect = Standard_True; + Handle(V3d_View) aView; + if (!aDumpFile.IsEmpty()) + { + ViewerTest::ViewerInit (0, 0, anImgParams.Width, anImgParams.Height, "TmpDriver/TmpViewer/TmpView"); + aView = ViewerTest::CurrentView(); + aView->SetImmediateUpdate (false); + aView->SetBgGradientStyle (Aspect_GFM_NONE, false); + } + + if (!aDumpFile.IsEmpty()) + { + OSD_OpenStream (anHtmlFile, aDumpFile.ToCString(), std::ios::out | std::ios::binary); + if (!anHtmlFile.is_open()) + { + std::cout << "Error: unable creating HTML file\n"; + return 0; + } + anHtmlFile << "\n" + << "OCCT Color table\n" + << "\n" + << "\n" + << "\n" + << "\n" + << "\n" + << "\n" + << "\n" + << "\n" + << "\n" + << "\n"; + } + + Image_AlienPixMap anImg; + Standard_Integer aColIndex = 0; + for (NCollection_Sequence::Iterator aColIter (aColList); aColIter.More(); aColIter.Next(), ++aColIndex) + { + Quantity_Color aCol (aColIter.Value()); + const TCollection_AsciiString aColName = Quantity_Color::StringName (aColIter.Value()); + const TCollection_AsciiString anSRgbHex = Quantity_Color::ColorToHex (aCol); + const Graphic3d_Vec3i anSRgbInt ((Graphic3d_Vec3 )aCol * 255.0f); + if (anHtmlFile.is_open()) + { + const TCollection_AsciiString anImgPath = aFileNameBase + "_" + aColName + ".png"; + if (!aView.IsNull()) + { + aView->SetImmediateUpdate (false); + aView->SetBackgroundColor (aCol); + if (!aView->ToPixMap (anImg, anImgParams) + || !anImg.Save (aFolder + anImgPath)) + { + theDI << "Error: image dump failed\n"; + return 0; + } + } + + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + anHtmlFile << "\n"; + } + else + { + TCollection_AsciiString aColNameLong (aColName); + aColNameLong.RightJustify (aMaxNameLen, ' '); + theDI << aColNameLong << " [" << anSRgbHex << "]: " << aCol.Red() << " " << aCol.Green() << " " << aCol.Blue() << "\n"; + } + } + + if (!aView.IsNull()) + { + ViewerTest::RemoveView (aView); + } + + if (anHtmlFile.is_open()) + { + anHtmlFile << "
HTMLOCCTColor namesRGB hexsRGB decRGB linear
       
" << aColName << "
" << anSRgbHex << "
(" << anSRgbInt.r() << " " << anSRgbInt.g() << " " << anSRgbInt.b() << ")(" << aCol.Red() << " " << aCol.Green() << " " << aCol.Blue() << ")
\n\n\n"; + } + return 0; +} + //======================================================================= //function : OpenGlCommands //purpose : @@ -910,4 +1380,18 @@ void ViewerTest::OpenGlCommands(Draw_Interpretor& theCommands) "\n\t\t: -reload restores dump of specified GLSL program", __FILE__, VShaderProg, aGroup); theCommands.Add("vshaderprog", "Alias for vshader", __FILE__, VShaderProg, aGroup); + theCommands.Add("vlistmaterials", + "vlistmaterials [*] [MaterialName1 [MaterialName2 [...]]] [dump.obj|dump.html]" + "\n\t\t: Without arguments, command prints the list of standard materials." + "\n\t\t: Otherwise, properties of specified materials will be printed" + "\n\t\t: or dumped into specified file." + "\n\t\t: * can be used to refer to complete list of standard materials.", + __FILE__, VListMaterials, aGroup); + theCommands.Add("vlistcolors", + "vlistcolors [*] [ColorName1 [ColorName2 [...]]] [dump.html]" + "\n\t\t: Without arguments, command prints the list of standard colors." + "\n\t\t: Otherwise, properties of specified colors will be printed" + "\n\t\t: or dumped into specified file." + "\n\t\t: * can be used to refer to complete list of standard colors.", + __FILE__, VListColors, aGroup); } diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index b7a2b56d0f..833ac10d93 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -14247,7 +14247,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)" "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)" "\n '-shadingModel model' Controls shading model from enumeration" - "\n color, flat, gouraud, phong" + "\n unlit, flat, gouraud, phong" "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size" "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)" "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect" diff --git a/tests/v3d/materials/colors b/tests/v3d/materials/colors new file mode 100644 index 0000000000..75d65cc1ae --- /dev/null +++ b/tests/v3d/materials/colors @@ -0,0 +1,32 @@ +puts "========" +puts "0030930: Draw Harness, ViewerTest - add commands vlistcolors and vlistmaterials listing standard Colors and Materials" +puts "Generate a table of predefined Colors (Quantity_NameOfColor enumeration)" +puts "========" + +pload MODELING VISUALIZATION +box b 10 10 10 +explode b F + +vclear +vclose ALL +vinit View1 +vtop + +puts "Color Comparison Table" + +set aColors [vlistcolors] +set anY 0 +set anX 0 +foreach aColor $aColors { + puts "$aColor" + tcopy b_6 ${aColor} + vdisplay -noUpdate -dispMode 1 ${aColor} + vaspects -noUpdate ${aColor} -setShadingModel unlit -setColor ${aColor} + vlocation -noUpdate ${aColor} -setLocation [expr 12*$anX] [expr 12*$anY] 0 + set anX [expr $anX+1] + if { $anX > 25 } { set anX 0; set anY [expr $anY+1] } +} +vfit + +vdump $::imagedir/${::casename}.png +vlistcolors $::imagedir/${::casename}_table.html diff --git a/tests/v3d/materials/materials b/tests/v3d/materials/materials new file mode 100644 index 0000000000..dd2df2c37d --- /dev/null +++ b/tests/v3d/materials/materials @@ -0,0 +1,21 @@ +puts "========" +puts "0030930: Draw Harness, ViewerTest - add commands vlistcolors and vlistmaterials listing standard Colors and Materials" +puts "Generate a table of predefined Materials (Graphic3d_NameOfMaterial enumeration)" +puts "========" + +pload XDE OCAF MODELING VISUALIZATION + +catch { Close D } +vclear +vinit View1 +vaxo + +puts "Material Comparison Table" +vlistmaterials $::imagedir/${::casename}.obj +ReadObj D $::imagedir/${::casename}.obj + +XDisplay -dispMode 1 D -explore +vfit +vdump ${imagedir}/${casename}.png + +vlistmaterials $::imagedir/${::casename}_table.html