Difference between revisions of "Colormodel kelvin"

From The Foundry MODO SDK wiki
Jump to: navigation, search
 
Line 21: Line 21:
 
The last two functions query the user for the max and min values of the color model.  
 
The last two functions query the user for the max and min values of the color model.  
  
 +
<syntaxhighlight>
 
  class CKelvinColorModelLog : public CLxLuxologyLogMessage
 
  class CKelvinColorModelLog : public CLxLuxologyLogMessage
 
  {
 
  {
Line 31: Line 32:
 
     ...
 
     ...
 
  };
 
  };
 +
</syntaxhighlight>
  
 
===[[Server_Tags|Server tags]]===
 
===[[Server_Tags|Server tags]]===
Line 38: Line 40:
 
This function here declares some basic information about the server.
 
This function here declares some basic information about the server.
  
 +
<syntaxhighlight>
 
  LXtTagInfoDesc CKelvinColorModel::descInfo[] = {
 
  LXtTagInfoDesc CKelvinColorModel::descInfo[] = {
 
         { LXsLOD_CLASSLIST,          LXa_COLORMODEL      },
 
         { LXsLOD_CLASSLIST,          LXa_COLORMODEL      },
Line 45: Line 48:
 
         { 0 }
 
         { 0 }
 
  };
 
  };
 +
</syntaxhighlight>
  
 
===[[Initialize_(index)|Intialization]]===
 
===[[Initialize_(index)|Intialization]]===
Line 52: Line 56:
 
In this case we add the ColorModel interface, depend upon the CKelvinColorModel class, and name our server kelvin_color_model.
 
In this case we add the ColorModel interface, depend upon the CKelvinColorModel class, and name our server kelvin_color_model.
  
 +
<syntaxhighlight>
 
         void
 
         void
 
  initialize ()
 
  initialize ()
Line 57: Line 62:
 
         LXx_ADD_SERVER (ColorModel, CKelvinColorModel, "kelvin_color_model");
 
         LXx_ADD_SERVER (ColorModel, CKelvinColorModel, "kelvin_color_model");
 
  }
 
  }
 +
</syntaxhighlight>
  
 
===Helper Functions===
 
===Helper Functions===
Line 62: Line 68:
 
This is a helper function that queries the user for a value. It is later called in the MaxTemp and MinTemp functions.
 
This is a helper function that queries the user for a value. It is later called in the MaxTemp and MinTemp functions.
  
 +
<syntaxhighlight>
 
         static int
 
         static int
 
  GetUserInt (const char *prefKey, int defaultValue = 0)
 
  GetUserInt (const char *prefKey, int defaultValue = 0)
Line 67: Line 74:
 
         ...
 
         ...
 
  }
 
  }
 +
</syntaxhighlight>
  
 
These are helper functions that query the user for the max and min values of the temperature of the graph. To query the user, this function calls the GetUserInt function. These functions are themselves called in a function that set the constants that govern the range of components in the graph and functions that draw slices of the graph.
 
These are helper functions that query the user for the max and min values of the temperature of the graph. To query the user, this function calls the GetUserInt function. These functions are themselves called in a function that set the constants that govern the range of components in the graph and functions that draw slices of the graph.
  
 +
<syntaxhighlight>
 
         unsigned
 
         unsigned
 
  CKelvinColorModel::MinTemp () const
 
  CKelvinColorModel::MinTemp () const
Line 81: Line 90:
 
         ...
 
         ...
 
  }  
 
  }  
 +
</syntaxhighlight>
  
 
===Implementations===
 
===Implementations===
Line 86: Line 96:
 
This function calculates imgX and imgY in (0..imgW, 0..imgH), from hsv color components on the plane specified by xAxis, yAxis.
 
This function calculates imgX and imgY in (0..imgW, 0..imgH), from hsv color components on the plane specified by xAxis, yAxis.
  
 +
<syntaxhighlight>
 
         LxResult
 
         LxResult
 
  CKelvinColorModel::colm_ToSlicePos (
 
  CKelvinColorModel::colm_ToSlicePos (
Line 98: Line 109:
 
       ...
 
       ...
 
  }
 
  }
 +
</syntaxhighlight>
  
 
This function calculates color model components hsv using imgX and imgY in [0, 1], on the plane specified by xAxis, yAxis.
 
This function calculates color model components hsv using imgX and imgY in [0, 1], on the plane specified by xAxis, yAxis.
 
NOTE: The other axis (the one that is neither x nor y) component value should already be set by the last bar selection or the initial color load.
 
NOTE: The other axis (the one that is neither x nor y) component value should already be set by the last bar selection or the initial color load.
  
 +
<syntaxhighlight>
 
         LxResult  
 
         LxResult  
 
  CKelvinColorModel::colm_FromSlicePos (
 
  CKelvinColorModel::colm_FromSlicePos (
Line 115: Line 128:
 
         ...
 
         ...
 
  }
 
  }
 +
</syntaxhighlight>
  
 
This function returns a clean vector so the color picker can drawn the horizontal strip properly.  For hue, this is 0,1,1, for saturation we set the value to 1 but leave the rest alone,, and for value it's always 0,0,0.
 
This function returns a clean vector so the color picker can drawn the horizontal strip properly.  For hue, this is 0,1,1, for saturation we set the value to 1 but leave the rest alone,, and for value it's always 0,0,0.
  
 +
<syntaxhighlight>
 
         LxResult
 
         LxResult
 
  CKelvinColorModel::colm_StripBaseVector (
 
  CKelvinColorModel::colm_StripBaseVector (
Line 126: Line 141:
 
         ...
 
         ...
 
  }
 
  }
 +
</syntaxhighlight>
  
 
[[Category: SDK Examples]]
 
[[Category: SDK Examples]]

Latest revision as of 18:13, 16 September 2013

Colormodel_kelvin is a basic example plugin. This wiki page is intended as a walkthrough of the code in order to help you better understand the SDK.

When installed, this plugin adds a color model that enables picking colors using a Kelvin color temperature component.

Kelvin shot1.png

The Kelvin color model

Code Walkthrough

Class Declarations

kelvincolormodel.h

There are two class declarations here. The first function inherits from CLxLuxologyLogMessage, which is the same as inheriting from ClxLogMessage but with an added Luxology copyright. Inside the class we have a CKelvinColorModelLog which defines what we will actually be writing out to the log. An object of this type is defined in our CKelvinColorModel class so it writes out to the log when the server dependent on it is used.

The second function inherits from CLxImpl_ColorModel because it has the functions we need in order to create our color model, which we want the CKelvinColorModel to create. It first declares a log object for the color model so that this class will output to the log. We then declare a Tag interface description so we can create some server tags, which indicate to Modo certain information about the server.

The rest of the functions(except for the last two) in the CKelvinModel are redeclarations of function present in CLxImplColorModel, which we inherited from. How CLxImplColorModel works is it defines a bunch of functions, but then indicates that it will not be implementing them. By redeclaring them, we indicate that we want to customize whatever that function affects. For example, we redeclare the function colm_ComponentType here and then later in the definition indicate that the component type of our color model will be float.

The last two functions query the user for the max and min values of the color model.

 class CKelvinColorModelLog : public CLxLuxologyLogMessage
 {
      ...
 };
 
 class CKelvinColorModel :
        public CLxImpl_ColorModel
 {
     ...
 };

Server tags

Servers tags are examined when the server is initialized, and give information about the server. We set the tags in this case by taking a descinfo[] array and associating the relevant data with the corresponding flags.

This function here declares some basic information about the server.

 LXtTagInfoDesc	 CKelvinColorModel::descInfo[] = {
        { LXsLOD_CLASSLIST,          LXa_COLORMODEL       },
        { LXsSRV_USERNAME,	     "Kelvin"             },
        { LXsSRV_LOGSUBSYSTEM,	     "kelvin-color-model" },
        { LXsCOLORMODEL_VALUEPRESET, "0:kelvin"	          },
        { 0 }
 };

Intialization

Servers are extensible set of features that we add to modo, usually through plugins. Intialize is called when we add the plugin to modo, and is the utility that exports the server. The LXx_ADD_SERVER method is simply a wrapper that is identical to normal method of adding a server, with the arguments being (interface_to_be_added, class_you_depend_on, server_name).

In this case we add the ColorModel interface, depend upon the CKelvinColorModel class, and name our server kelvin_color_model.

        void
 initialize ()
 {
        LXx_ADD_SERVER (ColorModel, CKelvinColorModel, "kelvin_color_model");
 }

Helper Functions

This is a helper function that queries the user for a value. It is later called in the MaxTemp and MinTemp functions.

        static int
 GetUserInt (const char *prefKey, int defaultValue = 0)
 {
        ...
 }

These are helper functions that query the user for the max and min values of the temperature of the graph. To query the user, this function calls the GetUserInt function. These functions are themselves called in a function that set the constants that govern the range of components in the graph and functions that draw slices of the graph.

        unsigned
 CKelvinColorModel::MinTemp () const
 {
       ...
 }
 
        unsigned
 CKelvinColorModel::MaxTemp () const
 {
        ...
 }

Implementations

This function calculates imgX and imgY in (0..imgW, 0..imgH), from hsv color components on the plane specified by xAxis, yAxis.

        LxResult
 CKelvinColorModel::colm_ToSlicePos (
        unsigned	 xAxis,
        unsigned	 yAxis,
        unsigned	 imgW,
        unsigned	 imgH,
        const float	*kelvin,
        unsigned	*imgX,
        unsigned	*imgY)
 {
       ...
 }

This function calculates color model components hsv using imgX and imgY in [0, 1], on the plane specified by xAxis, yAxis. NOTE: The other axis (the one that is neither x nor y) component value should already be set by the last bar selection or the initial color load.

        LxResult 
 CKelvinColorModel::colm_FromSlicePos (
        unsigned	 xAxis,
        unsigned	 yAxis,
        unsigned	 imgW,
        unsigned	 imgH,
        unsigned	 imgX,
        unsigned	 imgY,
        float		*downVec,
        float		*kelvin)
 {
        ...
 }

This function returns a clean vector so the color picker can drawn the horizontal strip properly. For hue, this is 0,1,1, for saturation we set the value to 1 but leave the rest alone,, and for value it's always 0,0,0.

        LxResult
 CKelvinColorModel::colm_StripBaseVector (
        unsigned	 axis,
        int		 dynamic,
        float		*kelvin)
 {
        ...
 }