void kGUIMovieObj::CalcChildZone(void) { int mch=m_moviecontrols.GetZoneH(); SetChildZone(0,0,GetZoneW(),GetZoneH()); m_image.SetPos(0,0); m_image.SetSize(GetZoneW(),GetZoneH()-mch); m_moviecontrols.SetPos(0,GetZoneH()-mch); m_moviecontrols.SetZoneW(GetZoneW()); /* allocate output image area */ m_image.SetMemImageCopy(0,GUISHAPE_SURFACE,m_image.GetZoneW(),m_image.GetZoneH(),4,0); SetOutputImage(&m_image,GetQuality()); }
void avtRayCompositer::Execute(void) { int i, j; avtVolume *volume = GetTypedInput()->GetVolume(); if (volume == NULL) { // This comes up in the following scenario: // An internal error occurs in the sampling phase. An exception is // thrown. That exception causes avtSamplePoints::SetVolume to be // not called. When its not called, its data member "volume" is // not initialized. So we get a NULL here. // // So: in summary, we only get into this situation if there was an // error before this module was called. EXCEPTION0(ImproperUseException); } // // Determine the size of the screen. // int height = volume->GetRestrictedVolumeHeight(); int width = volume->GetRestrictedVolumeWidth(); // // This is a test to determine if there is nothing in the partition we // are supposed to composite -- since we don't have access to the // partition, this is a bit of a hack and assumes how the partitioning // is done. // if (volume->GetRestrictedMinHeight() >= volume->GetVolumeHeight() || height <= 0 || width <= 0) { SetOutputImage(NULL); return; } volume->SetProgressCallback(RCPixelProgressCallback, this); // // Create an image that we can place each pixel into. // vtkImageData *image = avtImageRepresentation::NewImage(width, height); // // Populate an initial image, either with the background or with an // opaque image that is to be inserted into the middle of the rendering. // unsigned char *data = (unsigned char *)image->GetScalarPointer(0, 0, 0); int nPixels = width*height; double *zbuffer = new double[nPixels]; for (i = 0 ; i < nPixels ; i++) { zbuffer[i] = 1.; } // // Draw the initial background into the image. // int fullHeight = volume->GetVolumeHeight(); int fullWidth = volume->GetVolumeWidth(); vtkImageData *fullImage = avtImageRepresentation::NewImage(fullWidth, fullHeight); unsigned char *fulldata = (unsigned char *) fullImage->GetScalarPointer(0, 0, 0); FillBackground(fulldata, fullWidth, fullHeight); // // Now that we have the background in the full image, copy it into what // we need for this image. // int minWidth = volume->GetRestrictedMinWidth(); int minHeight = volume->GetRestrictedMinHeight(); for (i = 0 ; i < nPixels ; i++) { int restrictedWidth = i % width; int restrictedHeight = i / width; int realWidth = restrictedWidth + minWidth; int realHeight = restrictedHeight + minHeight; int indexIntoFullData = realHeight*fullWidth + realWidth; for (j = 0 ; j < 3 ; j++) { data[3*i+j] = fulldata[3*indexIntoFullData+j]; } } // // We were given an opaque image to insert into the picture. Worse, // the image probably has different dimensions if we are running in // parallel. This is captured by the notion of a restricted volume. // if (*opaqueImage != NULL) { int minW = volume->GetRestrictedMinWidth(); int minH = volume->GetRestrictedMinHeight(); vtkImageData *opaqueImageVTK = opaqueImage->GetImage().GetImageVTK(); float *opaqueImageZB = opaqueImage->GetImage().GetZBuffer(); unsigned char *opaqueImageData = (unsigned char *)opaqueImageVTK->GetScalarPointer(0, 0, 0); int n_comp = opaqueImageVTK->GetNumberOfScalarComponents(); for (int i = 0 ; i < width ; i++) { for (int j = 0 ; j < height ; j++) { int index = j*width + i; int opaqueImageIndex = (j+minH)*fullWidth + (i+minW); zbuffer[index] = opaqueImageZB[opaqueImageIndex]; if (zbuffer[index] != 1.) { data[3*index ] = opaqueImageData[n_comp*opaqueImageIndex]; data[3*index + 1] = opaqueImageData[n_comp*opaqueImageIndex+1]; data[3*index + 2] = opaqueImageData[n_comp*opaqueImageIndex+2]; } } } } // // Have the volume cast our ray function on all of its valid rays and put // the output in this screen. There is a lot of work here. // volume->GetPixels(rayfoo, data, zbuffer); // // Tell our output what its new image is. // SetOutputImage(image); // // Clean up memory. // image->Delete(); fullImage->Delete(); delete [] zbuffer; }
void avtWholeImageCompositerWithZ::Execute(void) { int numRows = 0; int numCols = 0; float *ioz = NULL; float *rioz = NULL; unsigned char *iorgb = NULL; unsigned char *riorgb = NULL; vtkImageData *mergedLocalImage = NULL; vtkImageData *mergedGlobalImage = NULL; // sanity checks if (inputImages.size() == 0) EXCEPTION0(ImproperUseException); for (size_t i = 0; i < inputImages.size(); i++) { inputImages[i]->GetImage().GetSize(&numRows, &numCols); if (numRows != outRows || numCols != outCols) EXCEPTION0(ImproperUseException); } int nPixels = outRows * outCols; avtImageRepresentation &zeroImageRep = inputImages[0]->GetImage(); if (inputImages.size() > 1) { // // Merge within a processor // int t1 = visitTimer->StartTimer(); mergedLocalImage = avtImageRepresentation::NewImage(outCols, outRows); visitTimer->StopTimer(t1, "Allocating image"); iorgb = (unsigned char *) mergedLocalImage->GetScalarPointer(0, 0, 0); ioz = new float [nPixels]; float *z0 = zeroImageRep.GetZBuffer(); const unsigned char *rgb0 = zeroImageRep.GetRGBBuffer(); // we memcpy because we can't alter any of the input images int t2 = visitTimer->StartTimer(); memcpy(ioz, z0, nPixels * sizeof(float)); memcpy(iorgb, rgb0, nPixels * 3 * sizeof(unsigned char)); visitTimer->StopTimer(t2, "Mem copies"); // do the merges, accumulating results in ioz and iorgb int t3 = visitTimer->StartTimer(); for (size_t i = 1; i < inputImages.size(); i++) { float *z = NULL; z = inputImages[i]->GetImage().GetZBuffer(); const unsigned char *rgb = inputImages[i]->GetImage().GetRGBBuffer(); MergeBuffers(nPixels, false, z, rgb, ioz, iorgb); } visitTimer->StopTimer(t3, "merging multiple images"); } else { mergedLocalImage = NULL; ioz = zeroImageRep.GetZBuffer(); iorgb = zeroImageRep.GetRGBBuffer(); } if (mpiRoot >= 0) { // only root allocates output AVT image (for a non-allreduce) if (allReduce || mpiRank == mpiRoot) { mergedGlobalImage = avtImageRepresentation::NewImage(outCols, outRows); riorgb = (unsigned char *) mergedGlobalImage->GetScalarPointer(0, 0, 0); rioz = new float [nPixels]; } // // Merge across processors // int t4 = visitTimer->StartTimer(); MergeBuffers(nPixels, true, ioz, iorgb, rioz, riorgb); visitTimer->StopTimer(t4, "MergeBuffers"); if (mergedLocalImage != NULL) { mergedLocalImage->Delete(); delete [] ioz; } if (allReduce || mpiRank == mpiRoot) { if (shouldOutputZBuffer) { avtImageRepresentation theOutput(mergedGlobalImage,rioz,true); SetOutputImage(theOutput); } else { delete [] rioz; avtImageRepresentation theOutput(mergedGlobalImage); SetOutputImage(theOutput); } mergedGlobalImage->Delete(); } else { avtImageRepresentation theOutput(NULL); SetOutputImage(theOutput); } } else { if (mergedLocalImage != NULL) { if (shouldOutputZBuffer) { avtImageRepresentation theOutput(mergedLocalImage,ioz,true); SetOutputImage(theOutput); } else { delete [] ioz; avtImageRepresentation theOutput(mergedLocalImage); SetOutputImage(theOutput); } mergedLocalImage->Delete(); } else { avtImageRepresentation theOutput(zeroImageRep); SetOutputImage(theOutput); } } }