Region& Region::Exclude(const Region &ex) { BeginOperation(); Region temp(ex); temp.Invert(); Intersect(temp); EndOperation(); return *this; }
Region& Region::Include(const Region ®ion) { BeginOperation(); for (int i = 0; i < region.CountRects(); i++) Include(region.RectAt(i)); EndOperation(); return *this; }
Region& Region::Invert() { BeginOperation(); Region temp; temp.Include(Rect(-COORD_MAX, -COORD_MAX, COORD_MAX, COORD_MAX)); for (int i = 0; i < fNumRects; i++) temp.Exclude(fRects[i]); SetTo(temp); EndOperation(); return *this; }
Region& Region::Include(const Rect &rect) { Region temp; BeginOperation(); // Make sure that there are no overlaps temp.AddRect(rect); for (int i = 0; i < fNumRects; i++) temp.Exclude(RectAt(i)); AddRegionRects(temp); EndOperation(); return *this; }
Region& Region::ConstrainTo(const Rect &rect) { BeginOperation(); for (int i = fNumRects - 1; i >= 0; i--) { fRects[i].left = max(rect.left, fRects[i].left); fRects[i].right = min(rect.right, fRects[i].right); fRects[i].top = max(rect.top, fRects[i].top); fRects[i].bottom = min(rect.bottom, fRects[i].bottom); if (!fRects[i].Valid()) RemoveRect(i); } EndOperation(); return *this; }
Region& Region::Intersect(const Region &intersectRegion) { BeginOperation(); Region newRegion; for (int i = 0; i < fNumRects; i++) { for (int j = 0; j < intersectRegion.fNumRects; j++) { if (RectAt(i).Intersects(intersectRegion.RectAt(j))) { Rect temp(RectAt(i)); temp.Intersect(intersectRegion.RectAt(j)); newRegion.AddRect(temp); } } } SetTo(newRegion); EndOperation(); return *this; }
Region& Region::Exclude(const Rect &excludeRect) { BeginOperation(); int index = 0; int rectsToCheck = fNumRects; while (index < rectsToCheck) { Rect &clipRect = fRects[index]; if (!excludeRect.Intersects(clipRect)) { index++; continue; } // This clip rect intersects the excluded rect, and could be divided into // as many as eight pieces. Test for each case. Note that none of these // rectangles overlap!!!! Rect quad1(clipRect.left, clipRect.top, excludeRect.left - 1, excludeRect.top - 1); if (SPLIT_TEST(clipRect, quad1)) { quad1.Intersect(clipRect); AddRect(quad1); } Rect quad2(excludeRect.left, clipRect.top, excludeRect.right, excludeRect.top - 1); if (SPLIT_TEST(clipRect, quad2)) { quad2.Intersect(clipRect); AddRect(quad2); } Rect quad3(excludeRect.right + 1, clipRect.top, clipRect.right, excludeRect.top - 1); if (SPLIT_TEST(clipRect, quad3)) { quad3.Intersect(clipRect); AddRect(quad3); } Rect quad4(clipRect.left, excludeRect.top, excludeRect.left - 1, excludeRect.bottom); if (SPLIT_TEST(clipRect, quad4)) { quad4.Intersect(clipRect); AddRect(quad4); } Rect quad5(excludeRect.right + 1, excludeRect.top, clipRect.right, excludeRect.bottom); if (SPLIT_TEST(clipRect, quad5)) { quad5.Intersect(clipRect); AddRect(quad5); } Rect quad6(clipRect.left, excludeRect.bottom + 1, excludeRect.left - 1, clipRect.bottom); if (SPLIT_TEST(clipRect, quad6)) { quad6.Intersect(clipRect); AddRect(quad6); } Rect quad7(excludeRect.left, excludeRect.bottom + 1, excludeRect.right, clipRect.bottom); if (SPLIT_TEST(clipRect, quad7)) { quad7.Intersect(clipRect); AddRect(quad7); } Rect quad8(excludeRect.right + 1, excludeRect.bottom + 1, clipRect.right, clipRect.bottom); if (SPLIT_TEST(clipRect, quad8)) { quad8.Intersect(clipRect); AddRect(quad8); } // This rect has been split, remove it. Note we don't // change the index RemoveRect(index); rectsToCheck--; } EndOperation(); return *this; }
void MolDisplayWin::WriteQTMovie(wxString & filepath) { //Create a QuickTime movie using the standard animation codecs with normal quality, and //temporal compression. The final file is flattened for cross platform compatability QTExport * QTOptions = new QTExport(this); //setup controls for the current data if (MainData->GetNumFrames() > 1) { //default to frame animation QTOptions->SetMovieChoice(0); } else { QTOptions->EnableFrameMovie(false); } if (MainData->cFrame->GetNumberNormalModes() <= 0) { QTOptions->EnableModeMovie(false); } if (QTOptions->ShowModal() != wxID_OK) { //user cancelled the operation QTOptions->Destroy(); return; } //retrieve the value of each option int MovieType = QTOptions->GetMovieChoice(); bool IncludeEPlot = QTOptions->AddEnergyPlot(); int compressorChoice = QTOptions->GetCompressorChoice(); int keyFrameRate = QTOptions->GetKeyFrameRate(); if (keyFrameRate < 0) keyFrameRate = 0; QTOptions->Destroy(); CodecType mCodec; switch (compressorChoice) { case 0: mCodec = kCinepakCodecType; break; case 1: mCodec = kGraphicsCodecType; break; case 2: mCodec = kAnimationCodecType; break; case 3: default: mCodec = kMPEG4VisualCodecType; } OSStatus s; OSErr myErr = myErr; FSSpec targetSpec; //ugh I need to get an FSSpec to hand to quicktime, but these calls only seem to work if //the file already exists... const char * t = filepath.mb_str(wxConvUTF8); FILE * temp = fopen(t, "wb"); fclose(temp); #ifdef __WXOSX_COCOA__ //This function is not found in the wxCocoa implementation, it is probably possible to work around it //Otherwise the code appears to link and run currently. However, it is probably better to redue the //code to use the Cocoa qtKit framework rather than the old Carbon QT library. //This path is not tested as the current Cocoa code does not properly support the extended save dialog. // void wxMacFilename2FSSpec( const wxString& path , FSSpec *spec ) { OSStatus err = noErr; FSRef fsRef; wxMacPathToFSRef( filepath , &fsRef ); err = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &targetSpec, NULL); verify_noerr( err ); } #else wxMacFilename2FSSpec(filepath, &targetSpec); #endif Movie theMovie = NULL; FSSpec tempSpec = targetSpec; strcpy((char *) &(tempSpec.name[1]), "MacMolPlt8933tempMovie"); tempSpec.name[0] = 22; BeginOperation(); ProgressInd->ChangeText("Creating movie..."); myErr = EnterMovies(); //initialize the quicktime manager if (myErr != noErr) { FinishOperation(); MessageAlert("Error initializing QuickTime!"); return; } //Create the movie file and initialize file data //Use Quicktime creator code 'TVOD' instead of simpletext 'ttxt' short resRefNum = 0; short resId = 0; myErr = CreateMovieFile(&tempSpec, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile, &resRefNum, &theMovie); if (myErr != noErr) { MessageAlert("Error creating movie file!"); } else { bool KillEPlot = false; int width, height, savedEPlotWidth, savedEPlotHeight; glCanvas->GetClientSize(&width, &height); Rect lDisplayRect={0,0,0,0}; lDisplayRect.right = width; lDisplayRect.bottom = height; Rect gRect = lDisplayRect; Rect EPlotRect = lDisplayRect; //If we are including an energy plot add space for it here if (IncludeEPlot && (MovieType == 0)) { EPlotRect.left = EPlotRect.right; EPlotRect.right = EPlotRect.left + height; if (!energyPlotWindow) { energyPlotWindow = new EnergyPlotDialog(this); KillEPlot = true; } else { energyPlotWindow->GetSize(&savedEPlotWidth, &savedEPlotHeight); } gRect.right += height; width += height; energyPlotWindow->Show(false); energyPlotWindow->SetSize(height, height); energyPlotWindow->Update(); //This is needed to initialise the window if we just created it } LocalToGlobal ((Point *) &(gRect.top)); LocalToGlobal ((Point *) &(gRect.bottom)); WindowRef TempWindow; s = CreateNewWindow(kDocumentWindowClass, kWindowNoAttributes, &gRect, &TempWindow); if (s == noErr) { //Create the video track Track theTrack = NewMovieTrack (theMovie, FixRatio(width,1), FixRatio(height,1), kNoVolume); if ((noErr == GetMoviesError())&&theTrack) { Media theMedia = NewTrackMedia (theTrack, VideoMediaType, 60, // Video Time Scale NULL, 0); if ((noErr == GetMoviesError())&&theMedia) { myErr = BeginMediaEdits (theMedia); if (myErr == noErr) { //create the actual movie frames GWorldPtr lgWorld=NULL; if (! NewGWorld (&lgWorld, 0, &gRect, (CTabHandle) NULL, (GDHandle) NULL, (GWorldFlags) (pixPurge + useTempMem))) { long MaxCompressedSize; ImageSequence seqID; ImageDescriptionHandle imageDesc = (ImageDescriptionHandle)NewHandle(4); PixMapHandle myPixMap = GetPortPixMap(lgWorld); LockPixels (myPixMap); myErr = CompressSequenceBegin(&seqID, myPixMap, NULL, &gRect, &gRect, 0, mCodec, bestCompressionCodec, codecNormalQuality, codecNormalQuality, keyFrameRate, NULL, codecFlagUpdatePreviousComp, imageDesc); GetMaxCompressionSize (myPixMap, &gRect, 0, codecNormalQuality, mCodec, (CompressorComponent) anyCodec, &MaxCompressedSize); Handle Buffer = TempNewHandle(MaxCompressedSize, &myErr); if (!Buffer) Buffer = NewHandle(MaxCompressedSize); if (Buffer) { qtData myqtData = {theMedia, imageDesc, seqID, lDisplayRect, gRect}; if (MovieType == 0) { CreateFrameMovie(lgWorld, Buffer, myqtData, IncludeEPlot); } else { CreateModeMovie(lgWorld, Buffer, myqtData); } DisposeHandle(Buffer); } myErr = CDSequenceEnd(seqID); if (lgWorld != NULL) DisposeGWorld (lgWorld); if (imageDesc) DisposeHandle((Handle) imageDesc); } myErr = EndMediaEdits (theMedia); } myErr = InsertMediaIntoTrack (theTrack, 0,/* track start time */ 0, /* media start time */ GetMediaDuration (theMedia), FixRatio(1,1)); } myErr = AddMovieResource (theMovie, resRefNum, &resId, NULL); } if (resRefNum) { //Create the actual file as a flat data fork so it can be placed on the www ProgressInd->ChangeText("Flattening movieÉ"); FlattenMovie(theMovie, flattenAddMovieToDataFork, &targetSpec, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile, &resId, NULL); CloseMovieFile (resRefNum); } DisposeWindow(TempWindow); } DisposeMovie (theMovie); DeleteMovieFile (&tempSpec); //delete the temp file after disposing of the movie if (energyPlotWindow) { if (KillEPlot) { delete energyPlotWindow; energyPlotWindow = NULL; } else { energyPlotWindow->SetSize(savedEPlotWidth, savedEPlotHeight); energyPlotWindow->FrameChanged(); energyPlotWindow->Show(true); } } } ExitMovies(); //Close out quicktime as we are done with it for now FinishOperation(); }