Difference between revisions of "Colormodel kelvin"

From The Foundry MODO SDK wiki
Jump to: navigation, search
Line 11: Line 11:
 
===Class Declarations===
 
===Class Declarations===
  
There are two class declarations here. The first function inherits from [[FAQ#Q:_How_do_I_write_to_the_log.3F|CLxLuxologyLogMessage]], which is the same as inheriting from [[Writing_to_the_Event_Log#CLxLogMessage|ClxLogMessage]] but with an added Luxology copyright. We inherit from this class in order to write out to the log. The second function inherits from [[Color_(lx-color.hpp)#ILxColorModel|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 and then declares a [[LXtTagInfoDesc_(index)#C23|Tag interface]] description so that the server can get a name and information. Following that, it redeclares some of the virtual functions declared in [[Color_(lx-color.hpp)#ILxColorModel|CLxImpl_ColorModel]] so that it can create a color model with the values it wants.  
+
kelvincolormodel.h
 +
 
 +
There are two class declarations here. The first function inherits from [[FAQ#Q:_How_do_I_write_to_the_log.3F|CLxLuxologyLogMessage]], which is the same as inheriting from [[Writing_to_the_Event_Log#CLxLogMessage|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 [[Color_(lx-color.hpp)#ILxColorModel|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 [[LXtTagInfoDesc_(index)#C23|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|Server tags]]===
 
===[[Server_Tags|Server tags]]===
  
This function declares some basic information about the server.
+
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[] = {
 
  LXtTagInfoDesc CKelvinColorModel::descInfo[] = {
Line 27: Line 48:
 
===[[Initialize_(index)|Intialization]]===
 
===[[Initialize_(index)|Intialization]]===
  
This function exports the server we've created based on the CKelvinColorModel class.
+
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
 
         void
Line 37: Line 60:
 
===Helper Functions===
 
===Helper Functions===
  
This is a helper function that queries the user for a value.
+
This is a helper function that queries the user for a value. It is later called in the MaxTemp and MinTemp functions.
  
 
         static int
 
         static int
Line 45: Line 68:
 
  }
 
  }
  
These are helper functions that return the constants that indicate that indicate the minimum and maximum values of the color model
+
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.
  
static const char* LXsUSER_VALUE_KELVIN_MIN_TEMP = "kelvinMinTemp";
 
static const char* LXsUSER_VALUE_KELVIN_MAX_TEMP = "kelvinMaxTemp";
 
 
 
         unsigned
 
         unsigned
 
  CKelvinColorModel::MinTemp () const
 
  CKelvinColorModel::MinTemp () const
Line 61: Line 81:
 
         ...
 
         ...
 
  }  
 
  }  
 +
 +
===Implementations===
  
 
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.

Revision as of 17:51, 12 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.

       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)
{
       ...
}