bool MT_bgcanvas::doMouseCallback(wxMouseEvent& event, double viewport_x, double viewport_y) { if(!g_bInpaint) { return MT_GLCanvasBase::doMouseCallback(event, viewport_x, viewport_y); } static long firstx = 0; static long firsty = 0; /*long x = event.GetX(); long y = GetSize().GetHeight() - event.GetY(); */ if(event.LeftDown()) { firstx = viewport_x; firsty = viewport_y; } if(event.LeftIsDown()) { g_CurrentRect = wxRect(MT_MIN(viewport_x,firstx),MT_MIN(viewport_y,firsty), fabs(firstx-viewport_x), fabs(firsty-viewport_y)); } Refresh(false); return MT_GLCanvasBase::doMouseCallback(event, viewport_x, viewport_y); }
CvRect unionOfCvRects(const CvRect& a, const CvRect&b) { int xmin = MT_MIN(a.x, b.x); int xmax = MT_MAX(a.x+a.width, b.x+b.width); int ymin = MT_MIN(a.y, b.y); int ymax = MT_MAX(a.y+a.height, b.y+b.height); return cvRect(xmin, ymin, xmax-xmin, ymax-ymin); }
CGPoint CGLineIntersectsRectAtPoint(CGRect rect, CGLine line) { CGLine top = CGLineMake( CGPointMake( CGRectGetMinX(rect), CGRectGetMinY(rect) ), CGPointMake( CGRectGetMaxX(rect), CGRectGetMinY(rect) ) ); CGLine right = CGLineMake( CGPointMake( CGRectGetMaxX(rect), CGRectGetMinY(rect) ), CGPointMake( CGRectGetMaxX(rect), CGRectGetMaxY(rect) ) ); CGLine bottom = CGLineMake( CGPointMake( CGRectGetMinX(rect), CGRectGetMaxY(rect) ), CGPointMake( CGRectGetMaxX(rect), CGRectGetMaxY(rect) ) ); CGLine left = CGLineMake( CGPointMake( CGRectGetMinX(rect), CGRectGetMinY(rect) ), CGPointMake( CGRectGetMinX(rect), CGRectGetMaxY(rect) ) ); // ensure the line extends beyond outside the rectangle CGFloat topLeftToBottomRight = CGPointDistance(CGRectTopLeftPoint(rect), CGRectBottomRightPoint(rect)); CGFloat bottomLeftToTopRight = CGPointDistance(CGRectBottomLeftPoint(rect), CGRectTopRightPoint(rect)); CGFloat maxDimension = MT_MAX(topLeftToBottomRight, bottomLeftToTopRight); CGFloat scaleFactor = maxDimension / MT_MIN(CGLineLength(line), maxDimension); CGLine extendedLine = CGLineScale(line, scaleFactor + 3); CGPoint points[4] = { CGLinesIntersectAtPoint(top, extendedLine), CGLinesIntersectAtPoint(right, extendedLine), CGLinesIntersectAtPoint(bottom, extendedLine), CGLinesIntersectAtPoint(left, extendedLine) }; for (int i = 0; i < 4; i++) { CGPoint p = points[i]; if (!CGPointEqualToPoint(p, NULL_POINT)) { return p; } } return NULL_POINT; }
MT_ExperimentDataFile::~MT_ExperimentDataFile() { /* close all the files */ for(unsigned int i = 0; i < MT_MIN(m_vpDataFiles.size(), m_viCheckedOut.size()); i++) { if(!m_viCheckedOut[i]) { /* fflush may not be necessary, but to make sure */ fflush(m_vpDataFiles[i]); fclose(m_vpDataFiles[i]); } } writeDataGroupToXML(&m_Settings); /* write the XML */ m_XMLFile.SaveFile(); }
std::string MT_CalculateRelativePath(const std::string& from_path, const std::string& to_path) { std::string::size_type from_length = from_path.size(); std::string::size_type to_length = to_path.size(); if(from_length == 0 || to_length == 0) { return from_path; } if(MT_PathIsAbsolute(from_path) != MT_PathIsAbsolute(to_path)) { return from_path; } #ifdef _WIN32 int common_levels = -1; #else int common_levels = 0; #endif unsigned int i = 0; unsigned int last_same_index = 0; for(i = 0; i < MT_MIN(from_length, to_length); i++) { if(from_path[i] != to_path[i]) { break; } if(from_path[i] == MT_PathSeparator) { last_same_index = i; common_levels++; } } std::string common_path = from_path.substr(0,last_same_index); std::string diff_path_to = to_path.substr(last_same_index); std::string diff_path_from = from_path.substr(last_same_index); if(diff_path_to[0] == MT_PathSeparator) { diff_path_to = diff_path_to.substr(1); } if(diff_path_from[0] == MT_PathSeparator) { diff_path_from = diff_path_from.substr(1); } std::stringstream ss; for(i = 0; i < diff_path_to.size(); i++) { if(diff_path_to[i] == MT_PathSeparator) { ss << "../"; } } ss << diff_path_from; return ss.str(); }
/* Drawing function - gets called by the GUI * All of the drawing is done with OpenGL */ void DanceTracker::doGLDrawing(int flags) { /* MT_R3 is a 3-vector class, used here for convenience */ MT_R3 blobcenter; /* m_bShowBlobs is a boolean in the "Drawing Options" data group. If the user selects "Drawing Options" from the "Tracking" menu, a dialog will pop up with a check box labeled "Show blob arrows", and its state will be linked (via a pointer) to the value of this variable */ if(m_bShowBlobs) { for (unsigned int i = 0; i < MT_MIN(m_vdBlobs_X.size(), m_vBlobs.size()); i++) { /* note that we have to subtract y from the frame_height to account for the window coordinates originating from the bottom left but the image coordinates originating from the top left */ blobcenter.setx(m_vdBlobs_X[i]); blobcenter.sety(m_iFrameHeight - m_vdBlobs_Y[i]); blobcenter.setz( 0 ); double M, m; M = MT_MAX(m_vBlobs[i].m_dMajorAxis, 0.01); m = MT_MAX(m_vBlobs[i].m_dMinorAxis, 0.01); MT_DrawEllipse(blobcenter, M, m, m_vBlobs[i].m_dOrientation, MT_Primaries[i % MT_NPrimaries]); /* draws an arrow using OpenGL */ /* MT_DrawArrow(blobcenter, // center of the base of the arrow * 20.0, // arrow length (pixels) * MT_DEG2RAD*m_vdBlobs_Orientation[i], // arrow angle * MT_Primaries[i % MT_NPrimaries], // color * 1.0 // fixes the arrow width * ); */ } } /* essentially the same as above, but with the tracked positions instead of the blob positions */ char s[50]; if(m_bShowTracking) { for (unsigned int i = 0; i < m_vdTracked_X.size(); i++) { blobcenter.setx(m_vdTracked_X[i]); blobcenter.sety(m_iFrameHeight - m_vdTracked_Y[i]); blobcenter.setz( 0 ); sprintf(s, "%d", i); printw(blobcenter.getx(), blobcenter.gety(), s); double th = atan2(-m_vdTracked_Vy[i], m_vdTracked_Vx[i]); MT_DrawArrow(blobcenter, 10.0, th, MT_Primaries[i % MT_NPrimaries], 0.5 ); } } double x1, y1, x2, y2; if(m_bShowInitialBlobs) { glLineStipple(1, 0x00FF); glEnable(GL_LINE_STIPPLE); for(unsigned int i = 0; i < m_vInitBlobs.size(); i++) { blobcenter.setx(m_vInitBlobs[i].COMx); blobcenter.sety(m_iFrameHeight - m_vInitBlobs[i].COMy); blobcenter.setz( 0 ); double M, m; M = MT_MAX(m_vInitBlobs[i].major_axis, 0.01); m = MT_MAX(m_vInitBlobs[i].minor_axis, 0.01); MT_DrawEllipse(blobcenter, M, m, m_vInitBlobs[i].orientation, MT_Green); } glDisable(GL_LINE_STIPPLE); } if(m_bShowAssociations) { glLineStipple(1, 0x00FF); glEnable(GL_LINE_STIPPLE); if(m_vInitBlobs.size() > 0 && m_viAssignments.size() > 0) { unsigned int max_label = MT_BiCC::getNumberOfLabels(m_viAssignments); for(unsigned int c = 0; c < max_label; c++) { for(unsigned int i = 0; i < m_iAssignmentRows; i++) { x1 = m_vdBlobs_X[i]; y1 = m_iFrameHeight - m_vdBlobs_Y[i]; for(unsigned int j = 0; j < m_iAssignmentCols; j++) { if(m_viAssignments[i] == c && m_viAssignments[m_iAssignmentRows + j] == c) { x2 = m_vInitBlobs[j].COMx; y2 = m_iFrameHeight - m_vInitBlobs[j].COMy; MT_DrawLineFromTo(x1, y1, x2, y2, MT_Red); } } } } } glDisable(GL_LINE_STIPPLE); } // MT_DrawRectangle(m_SearchArea.x, m_iFrameHeight - m_SearchArea.y - m_SearchArea.height, m_SearchArea.width, m_SearchArea.height); }