public override double getDistanceFromStartPoint(double row, double col) { double sRow = midR; // assumption: we have an angle starting at 0.0 double sCol = midC + 1 * radius; double angle = HMisc.AngleLl(midR, midC, sRow, sCol, midR, midC, row, col); if (angle < 0) { angle += 2 * Math.PI; } return(radius * angle); }
/// <summary> /// Recalculates the shape of the ROI. Translation is /// performed at the active handle of the ROI object /// for the image coordinate (x,y) /// </summary> public override void MoveByHandle(double newX, double newY) { HTuple distance; double dirX, dirY, prior, next, valMax, valMin; switch (activeHandleIdx) { case 0: // midpoint dirY = midR - newY; dirX = midC - newX; midR = newY; midC = newX; sizeR -= dirY; sizeC -= dirX; determineArcHandles(); break; case 1: // handle at circle border sizeR = newY; sizeC = newX; HOperatorSet.DistancePp(new HTuple(sizeR), new HTuple(sizeC), new HTuple(midR), new HTuple(midC), out distance); radius = distance[0].D; determineArcHandles(); break; case 2: // start handle for arc dirY = newY - midR; dirX = newX - midC; startPhi = Math.Atan2(-dirY, dirX); if (startPhi < 0) { startPhi = PI + (startPhi + PI); } setStartHandle(); prior = extentPhi; extentPhi = HMisc.AngleLl(midR, midC, startR, startC, midR, midC, extentR, extentC); if (extentPhi < 0 && prior > PI * 0.8) { extentPhi = (PI + extentPhi) + PI; } else if (extentPhi > 0 && prior < -PI * 0.7) { extentPhi = -PI - (PI - extentPhi); } break; case 3: // end handle for arc dirY = newY - midR; dirX = newX - midC; prior = extentPhi; next = Math.Atan2(-dirY, dirX); if (next < 0) { next = PI + (next + PI); } if (circDir == "positive" && startPhi >= next) { extentPhi = (next + TwoPI) - startPhi; } else if (circDir == "positive" && next > startPhi) { extentPhi = next - startPhi; } else if (circDir == "negative" && startPhi >= next) { extentPhi = -1.0 * (startPhi - next); } else if (circDir == "negative" && next > startPhi) { extentPhi = -1.0 * (startPhi + TwoPI - next); } valMax = Math.Max(Math.Abs(prior), Math.Abs(extentPhi)); valMin = Math.Min(Math.Abs(prior), Math.Abs(extentPhi)); if ((valMax - valMin) >= PI) { extentPhi = (circDir == "positive") ? -1.0 * valMin : valMin; } setExtentHandle(); break; } circDir = (extentPhi < 0) ? "negative" : "positive"; updateArrowHandle(); updateStartRect2XLDHandle(); }
//public HXLDCont GetXLDCont() //{ // HTuple row = this.row1.TupleConcat(this.row1[0]); // HTuple col = this.col1.TupleConcat(this.col1[0]); // HXLDCont hXLDCont = new HXLDCont(); // hXLDCont.GenEmptyObj(); // hXLDCont.GenContourPolygonXld(row, col); // return hXLDCont; //} /// <summary> /// Recalculates the shape of the ROI instance. Translation is /// performed at the active handle of the ROI object /// for the image coordinate (x,y) /// </summary> /// <param name="newX">x mouse coordinate</param> /// <param name="newY">y mouse coordinate</param> public override void moveByHandle(double newX, double newY) { if (this.minDistance >= 0.0) { if (this.activeHandleIdx < this.row1.TupleLength()) { double num; double d; if (this.activeHandleIdx != 0 && this.activeHandleIdx != this.row1.TupleLength() - 1) { num = HMisc.DistancePl(newY, newX, this.row1[this.activeHandleIdx - 1].D, this.col1[this.activeHandleIdx - 1].D, this.row1[this.activeHandleIdx + 1].D, this.col1[this.activeHandleIdx + 1].D); d = Math.Abs(HMisc.AngleLl(newY, newX, this.row1[this.activeHandleIdx - 1].D, this.col1[this.activeHandleIdx - 1].D, newY, newX, this.row1[this.activeHandleIdx + 1].D, this.col1[this.activeHandleIdx + 1].D)); } else if (this.activeHandleIdx == 0) { num = HMisc.DistancePl(newY, newX, this.row1[this.row1.TupleLength() - 1].D, this.col1[this.col1.TupleLength() - 1].D, this.row1[this.activeHandleIdx + 1].D, this.col1[this.activeHandleIdx + 1].D); d = Math.Abs(HMisc.AngleLl(newY, newX, this.row1[this.row1.TupleLength() - 1].D, this.col1[this.col1.TupleLength() - 1].D, newY, newX, this.row1[this.activeHandleIdx + 1].D, this.col1[this.activeHandleIdx + 1].D)); } else { num = HMisc.DistancePl(newY, newX, this.row1[this.activeHandleIdx - 1].D, this.col1[this.activeHandleIdx - 1].D, this.row1[0].D, this.col1[0].D); d = Math.Abs(HMisc.AngleLl(newY, newX, this.row1[this.activeHandleIdx - 1].D, this.col1[this.activeHandleIdx - 1].D, newY, newX, this.row1[0].D, this.col1[0].D)); } if (this.minDistance == 0.0) { this.row1[this.activeHandleIdx] = newY; this.col1[this.activeHandleIdx] = newX; this.minDistance = num; } else if (num >= this.minDistance) { this.row1[this.activeHandleIdx] = newY; this.col1[this.activeHandleIdx] = newX; this.minDistance = num; } else { HTuple hTuple = null; HOperatorSet.TupleDeg(d, out hTuple); if (Math.Abs(hTuple.D) > 179.5 && this.row1.TupleLength() > 2) { this.row1 = this.row1.TupleRemove(this.activeHandleIdx); this.col1 = this.col1.TupleRemove(this.activeHandleIdx); this.minDistance = -1.0; } else { this.row1[this.activeHandleIdx] = newY; this.col1[this.activeHandleIdx] = newX; this.minDistance = num; } } } else if (this.activeHandleIdx < this.row1.TupleLength() + this.row2.TupleLength()) { midR = newY; midC = newX; int num2 = this.activeHandleIdx - this.row1.TupleLength() + 1; this.row1 = this.row1.TupleInsert(num2, this.row2[num2 - 1].D); this.col1 = this.col1.TupleInsert(num2, this.col2[num2 - 1].D); this.activeHandleIdx = num2; } else if (this.activeHandleIdx == this.row1.TupleLength() + this.row2.TupleLength()) { double t = this.row0 - newY; double t2 = this.col0 - newX; this.row1 -= t; this.row2 -= t; this.col1 -= t2; this.col2 -= t2; } else { double t = this.row0 - newY; double t2 = this.col0 - newX; this.row1 -= t; this.row2 -= t; this.col1 -= t2; this.col2 -= t2; } midR = (row1.TupleMean() + row2.TupleMean()) / 2; midC = (col1.TupleMean() + col2.TupleMean()) / 2; this.updateRow2(); this.row0 = newY; this.col0 = newX; } } //end of class