#include <pathproc.h>
Inheritance diagram for ProcessPathDistance:
Public Member Functions | |
ProcessPathDistance (const double flat) | |
Constructor for ProcessPathDistance. | |
BOOL | GetCoordAndTangent (DocCoord *pCoord, double *pTangent, BOOL *pFound, double dist, Path *pPath, UINT32 *pPressure=NULL) |
Find the coords and tangent at a distance along a path If the distance is not actually on the path, extrapolate the ends of the. | |
INT32 | GetCoordAndTangentWithCache (DocCoord *pCoord, double *pTangent, BOOL *pFound, double dist, Path *pPath, UINT32 *pPressure=NULL) |
Find the coords and tangent at a distance along a path If the distance is not actually on the path, extrapolate the ends of the path as lines at the tangent at the last points and flag not (really) found This variant is designed for paths that use this function a lot. To avoid processsing the entire path many times we keep track of how many coords have already been processed. | |
virtual BOOL | NewPoint (PathVerb Verb, DocCoord *pCoord) |
Called from ProcessPath which has generated a new point on the open element. If the length of this line causes the cummulaive length to exceed the desired length, get the tangent of this line then use the remaing distance (Desired-Current) to linearly interpolate to the desired coord on the line. | |
BOOL | NewPointA (PathVerb Verb, DocCoord *pCoord, UINT32 *pPressure=NULL) |
Called from ProcessPath which has generated a new point on the open element. If the length of this line causes the cummulaive length to exceed the desired length, get the tangent of this line then use the remaing distance (Desired-Current) to linearly interpolate to the desired coord on the line. | |
INT32 | Process (const ProcessFlags &PFlags, INT32 AlreadyProcessed) |
Processes a path. It will scan through the elements of a path, passing points to a NewPoint virtual function. It will also flatten curves if found and pass the generated points on as well. | |
Private Attributes | |
double | DesiredDist |
double | CurrentDist |
double | TangentAtDist |
DocCoord | CoordAtDist |
UINT32 | PressureAtDist |
BOOL | Found |
DocCoord | PrevCoord |
UINT32 | m_PrevPressure |
INT32 | m_LastFoundIndex |
BOOL | m_bDrawingBrush |
double | m_LastFoundDistance |
Definition at line 276 of file pathproc.h.
|
Constructor for ProcessPathDistance.
Definition at line 936 of file pathproc.cpp. 00936 : ProcessPath(flat) 00937 { 00938 // just calls base class for now 00939 00940 // initialise caching members - DY 00941 m_LastFoundIndex = 0; 00942 m_LastFoundDistance = 0; 00943 CurrentDist = 0.0; 00944 m_bDrawingBrush = FALSE; 00945 }
|
|
Find the coords and tangent at a distance along a path If the distance is not actually on the path, extrapolate the ends of the.
Definition at line 965 of file pathproc.cpp. 00967 { 00968 ERROR2IF(pCoord==NULL && pTangent==NULL,FALSE,"ProcessPathDistance::GetCoordAndTangent() - no output pointers specified!"); 00969 ERROR2IF(pFound==NULL,FALSE,"ProcessPathDistance::GetCoordAndTangent() - pFound==NULL"); 00970 ERROR2IF( pPath==NULL,FALSE,"ProcessPathDistance::GetCoordAndTangent() - pPath==NULL"); 00971 00972 DesiredDist = Dist; 00973 CurrentDist = 0; 00974 Found = FALSE; 00975 CoordAtDist = DocCoord(0,0); 00976 TangentAtDist = 0; 00977 PressureAtDist = 0; 00978 00979 // set up the processpath process. 00980 ProcessFlags PFlags; 00981 BOOL ok=ProcessPath::Init(pPath); 00982 if (ok) ok= Process(PFlags, 0); //ProcessPath::Process(PFlags); 00983 00984 if (ok) 00985 { 00986 if (Found==FALSE) 00987 { 00988 // get last 2 points on line 00989 DocCoord* pPathCoords=pPath->GetCoordArray(); 00990 ERROR2IF(pPathCoords==NULL,FALSE,"ProcessPathDistance::GetCoordAndTangent() - pPathCoords==NULL"); 00991 INT32 NumPathCoords=pPath->GetNumCoords(); 00992 ERROR2IF(NumPathCoords<2,FALSE,"ProcessPathDistance::GetCoordAndTangent() - NumPathCoords < 2"); 00993 DocCoord LastCoord=pPathCoords[NumPathCoords-1]; 00994 DocCoord PrevCoord=pPathCoords[NumPathCoords-2]; 00995 00996 double dx=LastCoord.x-PrevCoord.x; 00997 double dy=LastCoord.y-PrevCoord.y; 00998 double LineLength=sqrt(dx*dx+dy*dy); 00999 01000 if (LineLength>0) 01001 { 01002 double FractOfLine = (DesiredDist-CurrentDist)/LineLength; 01003 double x = LastCoord.x+dx*FractOfLine; 01004 double y = LastCoord.y+dy*FractOfLine; 01005 01006 CoordAtDist = DocCoord((MILLIPOINT)x,(MILLIPOINT)y); 01007 TangentAtDist = atan2(dy,dx); 01008 } 01009 else 01010 { 01011 CoordAtDist = LastCoord; 01012 TangentAtDist = 0; 01013 } 01014 } 01015 else 01016 if (Dist<0) Found=FALSE; // if not actually on path, flag not found on path 01017 01018 01019 *pFound = Found; 01020 if (pCoord) *pCoord = CoordAtDist; 01021 if (pTangent) *pTangent = TangentAtDist; 01022 if (pPressure != NULL) 01023 { 01024 *pPressure = PressureAtDist; 01025 // TRACEUSER( "Diccon", _T("Pressure At Dist = %d\n"), PressureAtDist); 01026 } 01027 } 01028 01029 return ok; 01030 }
|
|
Find the coords and tangent at a distance along a path If the distance is not actually on the path, extrapolate the ends of the path as lines at the tangent at the last points and flag not (really) found This variant is designed for paths that use this function a lot. To avoid processsing the entire path many times we keep track of how many coords have already been processed.
Definition at line 1055 of file pathproc.cpp. 01058 { 01059 ERROR2IF(pCoord==NULL && pTangent==NULL,FALSE,"ProcessPathDistance::GetCoordAndTangent() - no output pointers specified!"); 01060 ERROR2IF(pFound==NULL,FALSE,"ProcessPathDistance::GetCoordAndTangent() - pFound==NULL"); 01061 ERROR2IF( pPath==NULL,FALSE,"ProcessPathDistance::GetCoordAndTangent() - pPath==NULL"); 01062 01063 // we wish to continue processing from the last point that we found 01064 INT32 PrevCoordIndex = m_LastFoundIndex; 01065 INT32 NumProcessed = m_LastFoundIndex; 01066 01067 DesiredDist = Dist; 01068 CurrentDist = m_LastFoundDistance; 01069 Found = FALSE; 01070 CoordAtDist = DocCoord(0,0); 01071 TangentAtDist = 0; 01072 PressureAtDist = 0; 01073 m_bDrawingBrush = TRUE; 01074 // set up the processpath process. 01075 ProcessFlags PFlags; 01076 01077 BOOL bPressure = (pPressure != NULL && pPath->HasWidth()); 01078 // if we are already partway along the path then we need to get the 01079 // previous point as it is needed in NewPoint 01080 if (NumProcessed > 0) 01081 { 01082 DocCoord* pCoords = pPath->GetCoordArray(); 01083 PrevCoord = pCoords[PrevCoordIndex]; 01084 if (bPressure) 01085 { 01086 UINT32* pPressureArray = pPath->GetWidthArray(); 01087 if (pPressureArray != NULL) 01088 m_PrevPressure = pPressureArray[PrevCoordIndex]; 01089 else 01090 { 01091 ERROR3("Wheres the pressure array?"); 01092 m_PrevPressure = (UINT32)(MAXPRESSURE / 2); 01093 } 01094 } 01095 } 01096 01097 BOOL ok=ProcessPath::Init(pPath); 01098 //TRACEUSER( "Diccon", _T("Desired = %f\n"), Dist); 01099 //TRACEUSER( "Diccon", _T("Starting = %f\n"), CurrentDist); 01100 01101 if (ok) NumProcessed = Process(PFlags, NumProcessed); 01102 01103 if (NumProcessed != -1) 01104 { 01105 if (Found==FALSE) // this can happen if we are on the first couple of points 01106 { 01107 // get last 2 points on line 01108 DocCoord* pPathCoords=pPath->GetCoordArray(); 01109 ERROR2IF(pPathCoords==NULL,FALSE,"ProcessPathDistance::GetCoordAndTangent() - pPathCoords==NULL"); 01110 INT32 NumPathCoords=pPath->GetNumCoords(); 01111 //ERROR2IF(NumPathCoords<2,FALSE,"ProcessPathDistance::GetCoordAndTangent() - NumPathCoords < 2"); 01112 if (NumPathCoords >= 2) 01113 { 01114 DocCoord LastCoord=pPathCoords[NumPathCoords-1]; 01115 DocCoord PrevCoord=pPathCoords[NumPathCoords-2]; 01116 01117 double dx=LastCoord.x-PrevCoord.x; 01118 double dy=LastCoord.y-PrevCoord.y; 01119 double LineLength=sqrt(dx*dx+dy*dy); 01120 01121 if (LineLength>0) 01122 { 01123 double FractOfLine = (DesiredDist-CurrentDist)/LineLength; 01124 double x = LastCoord.x+dx*FractOfLine; 01125 double y = LastCoord.y+dy*FractOfLine; 01126 01127 CoordAtDist = DocCoord((MILLIPOINT)x,(MILLIPOINT)y); 01128 TangentAtDist = atan2(dy,dx); 01129 Found = TRUE; 01130 } 01131 else 01132 { 01133 CoordAtDist = LastCoord; 01134 TangentAtDist = 0; 01135 Found = TRUE; 01136 } 01137 } 01138 else //if we only have one coordinate so far 01139 { 01140 CoordAtDist=pPathCoords[0]; 01141 TangentAtDist = 0; 01142 Found = TRUE; 01143 } 01144 } 01145 else 01146 { 01147 if (Dist<0) Found=FALSE; // if not actually on path, flag not found on path 01148 01149 } 01150 *pFound = Found; 01151 if (pCoord) *pCoord = CoordAtDist; 01152 if (pTangent) *pTangent = TangentAtDist; 01153 if (pPressure != NULL) 01154 *pPressure = PressureAtDist; 01155 } 01156 //m_LastFoundDistance = CurrentDist; 01157 //TRACEUSER( "Diccon", _T("Last Index = %d\n"), m_LastFoundIndex); 01158 //TRACEUSER( "Diccon", _T("Last Dist = %f\n"), m_LastFoundDistance); 01159 01160 //TRACEUSER( "Diccon", _T("FOUND = %d\n"), Found); 01161 01162 return NumProcessed; 01163 }
|
|
Called from ProcessPath which has generated a new point on the open element. If the length of this line causes the cummulaive length to exceed the desired length, get the tangent of this line then use the remaing distance (Desired-Current) to linearly interpolate to the desired coord on the line.
Implements ProcessPath. Definition at line 1178 of file pathproc.cpp. 01179 { 01180 ERROR2IF(pCoord==NULL,FALSE,"ProcessPathDistance::NewPoint() - pCoord==NULL"); 01181 ERROR2IF(Verb!=PT_LINETO && Verb!=PT_MOVETO,FALSE,"ProcessPathDistance::NewPoint() - unknown path verb"); 01182 01183 01184 if (!Found && !ProcFirstPoint && Verb==PT_LINETO) 01185 { 01186 double dx=pCoord->x-PrevCoord.x; 01187 double dy=pCoord->y-PrevCoord.y; 01188 double LineLength=sqrt(dx*dx+dy*dy); 01189 01190 double NextDist=CurrentDist+LineLength; 01191 01192 m_LastFoundDistance = CurrentDist; 01193 //TRACEUSER( "Diccon", _T("m_LastFound = %f\n"), m_LastFoundDistance); 01194 if (NextDist>=DesiredDist) 01195 { 01196 if (LineLength>0) 01197 { 01198 double FractOfLine = (DesiredDist-CurrentDist)/LineLength; 01199 double x = PrevCoord.x+dx*FractOfLine; 01200 double y = PrevCoord.y+dy*FractOfLine; 01201 CoordAtDist = DocCoord((MILLIPOINT)x,(MILLIPOINT)y); 01202 TangentAtDist = atan2(dy,dx); 01203 01204 } 01205 else 01206 { 01207 CoordAtDist = PrevCoord; 01208 TangentAtDist = 0; 01209 } 01210 Found=TRUE; 01211 } 01212 01213 CurrentDist=NextDist; 01214 } 01215 01216 PrevCoord=*pCoord; 01217 01218 return TRUE; 01219 }
|
|
Called from ProcessPath which has generated a new point on the open element. If the length of this line causes the cummulaive length to exceed the desired length, get the tangent of this line then use the remaing distance (Desired-Current) to linearly interpolate to the desired coord on the line.
Definition at line 1235 of file pathproc.cpp. 01236 { 01237 ERROR2IF(pCoord==NULL,FALSE,"ProcessPathDistance::NewPoint() - pCoord==NULL"); 01238 ERROR2IF(Verb!=PT_LINETO && Verb!=PT_MOVETO,FALSE,"ProcessPathDistance::NewPoint() - unknown path verb"); 01239 01240 01241 if (!Found && !ProcFirstPoint && Verb==PT_LINETO) 01242 { 01243 double dx=pCoord->x-PrevCoord.x; 01244 double dy=pCoord->y-PrevCoord.y; 01245 double LineLength=sqrt(dx*dx+dy*dy); 01246 01247 double NextDist=CurrentDist+LineLength; 01248 01249 m_LastFoundDistance = CurrentDist; 01250 //TRACEUSER( "Diccon", _T("m_LastFound = %f\n"), m_LastFoundDistance); 01251 if (NextDist>=DesiredDist) 01252 { 01253 if (LineLength>0) 01254 { 01255 double FractOfLine = (DesiredDist-CurrentDist)/LineLength; 01256 double x = PrevCoord.x+dx*FractOfLine; 01257 double y = PrevCoord.y+dy*FractOfLine; 01258 CoordAtDist = DocCoord((MILLIPOINT)x,(MILLIPOINT)y); 01259 TangentAtDist = atan2(dy,dx); 01260 if (pPressure != NULL) 01261 PressureAtDist = (UINT32)((*pPressure * (1-FractOfLine)) + (m_PrevPressure * FractOfLine)); 01262 } 01263 else 01264 { 01265 CoordAtDist = PrevCoord; 01266 TangentAtDist = 0; 01267 if (pPressure != NULL) 01268 PressureAtDist = m_PrevPressure; 01269 } 01270 Found=TRUE; 01271 } 01272 01273 CurrentDist=NextDist; 01274 } 01275 01276 PrevCoord=*pCoord; 01277 m_PrevPressure = *pPressure; 01278 return TRUE; 01279 }
|
|
Processes a path. It will scan through the elements of a path, passing points to a NewPoint virtual function. It will also flatten curves if found and pass the generated points on as well.
This variant only processes coordinates after AlreadyProcessed Definition at line 1307 of file pathproc.cpp. 01308 { 01309 01310 // The idea here is that we create a quantised path. This means we 01311 // scan through the path descretizing curves and lines dependent 01312 // on the flatness value given. 01313 01314 DocCoord* ICoords = ProcSource->GetCoordArray(); 01315 PathVerb* IVerbs = ProcSource->GetVerbArray(); 01316 01317 UINT32* IPressure = NULL; 01318 if (ProcSource->HasWidth()) 01319 IPressure = ProcSource->GetWidthArray(); 01320 01321 //if (IPressure == NULL) 01322 // ERROR3("No pressure array"); 01323 01324 INT32 numinsource = ProcSource->GetNumCoords(); 01325 01326 INT32 i=AlreadyProcessed; 01327 BOOL ok = TRUE; 01328 if ( i > 0) 01329 { 01330 ProcFirstPoint = FALSE; 01331 } 01332 01333 // scan through the input verbs 01334 while ((i < numinsource) && (ok) && (!Found)) 01335 { 01336 // if (IPressure != NULL) 01337 // TRACEUSER( "Diccon", _T("PathProc Pressure = %d\n"), IPressure[i]); 01338 switch (IVerbs[i] & ~PT_CLOSEFIGURE) 01339 { 01340 case PT_MOVETO: 01341 OpenElement(PT_MOVETO, i); 01342 if (IPressure != NULL) 01343 ok = NewPointA(PT_MOVETO, &ICoords[i], &IPressure[i]); 01344 else 01345 ok = NewPoint(PT_MOVETO, &ICoords[i]); 01346 01347 if (CloseElement(ok, PT_MOVETO, i)) 01348 i=(numinsource-1); 01349 break; 01350 01351 case PT_LINETO: 01352 { 01353 BOOL IsCloseFigure = ((IVerbs[i] & PT_CLOSEFIGURE) != 0); // Remember if this is the closing element 01354 01355 OpenElement(PT_LINETO, i); 01356 if (!PFlags.QuantiseAll) 01357 { 01358 if (!PFlags.QuantiseLines) 01359 if (IPressure != NULL) 01360 ok = NewPointA(PT_LINETO, &ICoords[i], &IPressure[i]); 01361 else 01362 ok = NewPoint(PT_LINETO, &ICoords[i]); 01363 else 01364 { 01365 DocCoord End = ICoords[i]; 01366 for (double mu = 0.2; (mu<1.2) && ok; mu+=0.2 ) 01367 { 01368 DocCoord dest; 01369 dest.x = (INT32)((1-mu)*ProcPreviousEl.x + mu*End.x); 01370 dest.y = (INT32)((1-mu)*ProcPreviousEl.y + mu*End.y); 01371 ok = NewPoint(PT_LINETO, &dest); 01372 } 01373 } 01374 } 01375 else 01376 { 01377 ok = InsertQuantisedLineTo(&ICoords[i], &ProcPreviousEl); 01378 } 01379 if (CloseElement(ok, PT_LINETO, i)) 01380 i=(numinsource-1); 01381 else if (IsCloseFigure) // If continuing, and this is the end of a closed figure 01382 CloseFigure(); // then close it off 01383 } 01384 break; 01385 01386 case PT_BEZIERTO: 01387 { 01388 BOOL IsCloseFigure = ((IVerbs[i+2] & PT_CLOSEFIGURE) != 0); // Remember if this is the closing element 01389 01390 OpenElement(PT_BEZIERTO, i); 01391 if (!PFlags.FlattenCurves) 01392 ok = NewPoint(PT_BEZIERTO, &ICoords[i]); 01393 else 01394 { 01395 ok = FlattenCurve(ProcPreviousEl.x, ProcPreviousEl.y, 01396 ICoords[i].x, ICoords[i].y, 01397 ICoords[i+1].x, ICoords[i+1].y, 01398 ICoords[i+2].x, ICoords[i+2].y, (PFlags.QuantiseAll) ); 01399 } 01400 if (CloseElement(ok, PT_BEZIERTO, i)) 01401 i=(numinsource-1); 01402 else 01403 { 01404 if (IsCloseFigure) // If continuing, and this is the end of a closed figure 01405 CloseFigure(); // then close it off 01406 01407 i+=2; 01408 } 01409 } 01410 break; 01411 01412 default: ERROR3("ProcessPath::Process() - unknown path verb!"); 01413 01414 } 01415 ICoords = ProcSource->GetCoordArray(); 01416 IVerbs = ProcSource->GetVerbArray(); 01417 i++; 01418 ProcFirstPoint = FALSE; 01419 ProcPreviousEl = ICoords[i-1]; 01420 } 01421 01422 // we are recording the point previous to the one we just found. 01423 // i represents the next point, i-1 is the point we just found, so 01424 // the one before that is i-2 01425 if (Found) 01426 m_LastFoundIndex = i -2; 01427 01428 INT32 ReturnValue; 01429 // we have processed i-1 points 01430 if (ok) 01431 ReturnValue = i-1; 01432 else 01433 ReturnValue = -1; 01434 01435 return ok; 01436 }
|
|
Definition at line 299 of file pathproc.h. |
|
Definition at line 297 of file pathproc.h. |
|
Definition at line 296 of file pathproc.h. |
|
Definition at line 301 of file pathproc.h. |
|
Definition at line 307 of file pathproc.h. |
|
Definition at line 308 of file pathproc.h. |
|
Definition at line 306 of file pathproc.h. |
|
Definition at line 303 of file pathproc.h. |
|
Definition at line 300 of file pathproc.h. |
|
Definition at line 302 of file pathproc.h. |
|
Definition at line 298 of file pathproc.h. |