00001
00012 #ifdef _MSC_VER
00013
00014 #include "msdevstudio/MSconfig.h"
00015 #endif //_MSC_VER
00016
00017 #include "LineFunctionRep.h"
00018
00019 #include "axes/Range.h"
00020 #include "functions/FunctionBase.h"
00021 #include "graphics/ViewBase.h"
00022 #include "transforms/BinaryTransform.h"
00023
00024 using namespace hippodraw;
00025
00026 LineFunctionRep::
00027 LineFunctionRep ()
00028 : LinePointRep ( "FunctionLine", 1.0 )
00029 {
00030 }
00031
00032 LineFunctionRep::
00033 LineFunctionRep ( float size )
00034 : LinePointRep ( "FunctionLine", size )
00035 {
00036 }
00037
00038 LineFunctionRep::
00039 LineFunctionRep ( const LineFunctionRep & point_rep )
00040 : LinePointRep ( point_rep )
00041 {
00042 }
00043
00044 LineFunctionRep::~LineFunctionRep ()
00045 {
00046 }
00047
00048 RepBase * LineFunctionRep::clone()
00049 {
00050 return new LineFunctionRep( *this );
00051 }
00052
00053 void
00054 LineFunctionRep::
00055 drawProjectedValues ( const Range & range,
00056 const FunctionBase * function,
00057 TransformBase * transform,
00058 ViewBase * view )
00059 {
00060 smoothCurve ( range, transform, function );
00061 drawValues ( view );
00062 }
00063
00064 void
00065 LineFunctionRep::
00066 smoothCurve ( const Range & range,
00067 TransformBase * transform,
00068 const FunctionBase * function )
00069 {
00070 const BinaryTransform * t
00071 = dynamic_cast < const BinaryTransform * > ( transform );
00072
00073 unsigned int size = 50;
00074 m_x.resize ( size );
00075 m_y.resize ( size );
00076
00077 double tx = range.low ();
00078 double ty = function -> operator () ( tx );
00079 t -> transform ( tx, ty );
00080 double txx = range.high ();
00081 double tyy = function -> operator () ( txx );
00082 t -> transform ( txx, tyy );
00083
00084 double x = tx;
00085 double delta = ( txx - tx ) / ( size - 1 );
00086
00087 for ( unsigned int i = 0; i < size; i++ ) {
00088 tx = x + 0.1 * delta;
00089 t -> inverseTransform ( tx, ty );
00090 ty = function -> operator () ( tx );
00091 t -> transform ( tx, ty );
00092 m_x [ i ] = tx;
00093 m_y [ i ] = ty;
00094
00095 x += delta;
00096 }
00097 }