void MonteCarloRayTracer::render(float *pixels, Octree *tree, Camera *cam) { const int NUM_THREADS = std::thread::hardware_concurrency(); _rgen = Rng(); std::cout << "Starting carlo tracer with " << NUM_THREADS << " threads.\n"; std::vector<std::thread> threads; // Start threads Timer::getInstance()->start("Carlo"); for (int row = 0; row < _H; ++row) { for (int i = 0; i < NUM_THREADS; ++i) { threads.push_back(std::thread(&MonteCarloRayTracer::threadRender, this, i, pixels, *tree, *cam, row, NUM_THREADS)); threadDone.push_back(false); } for (auto &thread : threads) { thread.join(); } threads.clear(); threadDone.clear(); glRender(pixels); } // Join threads std::cout << std::endl; Timer::getInstance()->stop("Carlo"); Timer::getInstance()->printRealTime("Carlo"); std::cout << "Mean depth: " << float(_meanRayDepth) / float(_W * _H * _raysPerPixel) << std::endl; }
/******************************************************************************************** > BOOL MakeBitmapFilter::DoCreateBitmap(Operation *pOp, Document *pDoc, KernelBitmap** ppBitmap) Author: Will_Cowling (Xara Group Ltd) <*****@*****.**> Created: 11/6/96 Purpose: Exports the current selection as a bitmap, via the virtual fns of the inherited class. Returns: TRUE if worked, FALSE if failed. SeeAlso: GetExportOptions; PrepareToExport; ExportRenderNodes; CleanUpAfterExport; ********************************************************************************************/ BOOL MakeBitmapFilter::DoCreateBitmap(Operation *pOp, Document *pDoc, KernelBitmap** ppBitmap) { ERROR3IF(ppBitmap == NULL, "NULL bitmap pointer passed to MakeBitmapFilter::DoCreateBitmap"); if (ppBitmap == NULL) return FALSE; pTheBitmap = NULL; *ppBitmap = NULL; // Set the bitmap pointer to null just in case, usually only used by DoExportBitmap pExportBitmap = NULL; // Get pointer to the spread to export. PORTNOTE("spread", "Multi-spread warning!") pSpread = GetFirstSpread(pDoc); // remember the document in the class variable TheDocument = pDoc; // We must now check if there is a selection present so that we can set up whether the // user gets the choice of exporting the selection, drawing or spread if there is a // selection present OR just a choice between the spread or drawing if no selection is // present. // If have a caret selected in a text story then the selection will be almost zero so trap // this case as well. RangeControl rg = GetApplication()->FindSelection()->GetRangeControlFlags(); rg.PromoteToParent = TRUE; GetApplication()->FindSelection()->Range::SetRangeControl(rg); SelRange Rng(*(GetApplication()->FindSelection())); // now, run through the selection selecting all nodes under all compound nodes // if we don't do this then all compound nodes aren't rendered correctly with transparent // bitmaps Node * pNode = Rng.FindFirst(FALSE); while (pNode) { pNode->SetSelected(FALSE); pNode->SetSelected(TRUE); pNode = Rng.FindNext(pNode, FALSE); } rg.PromoteToParent = FALSE; GetApplication()->FindSelection()->Range::SetRangeControl(rg); GetApplication()->UpdateSelection(); DocRect ClipRect = GetApplication()->FindSelection()->GetBoundingRect(); SelectionType Selection = DRAWING; if ( ClipRect.IsEmpty() || ClipRect.Width() < MinExportSize || ClipRect.Height() < MinExportSize) Selection = DRAWING; // no selection present, so choose drawing by default else Selection = SELECTION; // selection present, so choose this by default if (Selection != SELECTION) { BOOL UseDrawingBounds = TRUE; SelRange* pSel = GetApplication()->FindSelection(); if (pSel && pSel->Count()==1) { // Only one thing selected ... Is it the Text Caret per chance ? Node* pSelNode = pSel->FindFirst(); if (pSelNode && pSelNode->IsAVisibleTextNode()) { VisibleTextNode* pTextNode = (VisibleTextNode*)pSelNode; if (pTextNode->IsACaret()) { // Aha! It's the Caret that's selected. // We'll use the bounds of the parent text line instead then ... Node* pTextLine = pTextNode->FindParent(); ERROR3IF(!IS_A(pTextLine, TextLine), "Caret doesn't have a parent text line in DoCreateBitmap"); // Get the bounds of the text line ClipRect = ((TextLine*)pTextLine)->GetBoundingRect(); Selection = SELECTION; UseDrawingBounds = FALSE; } } } if (UseDrawingBounds) { // Work out the size of the rectangle encompassing the drawing (visible layers only) ClipRect = GetSizeOfDrawing(pSpread); } } // Create somewhere to put the user options and fill them up MakeBitmapExportOptions* pMakeBmpExportOptions = (MakeBitmapExportOptions*)CreateExportOptions(); if (pMakeBmpExportOptions == NULL) { Error::SetError(_R(IDS_OUT_OF_MEMORY)); return FALSE; } pMakeBmpExportOptions->RetrieveDefaults(); pMakeBmpExportOptions->SetDepth(32); // create bmp copies shoulda always default to being 32 bit pMakeBmpExportOptions->SetSelectionType(Selection); // Set the BaseBitmapFilter member so we can use base class functionality - blurghh SetExportOptions(pMakeBmpExportOptions); BOOL ok = GetExportOptions( (BitmapExportOptions*)pMakeBmpExportOptions ); BOOL IsAnimation = BmapPrevDlg::m_pExportOptions == NULL; BaseBitmapFilter * pNewFilter = this; BitmapExportOptions * pExportOptions = BmapPrevDlg::m_pExportOptions; if (!IsAnimation) { pNewFilter = pExportOptions->FindBitmapFilterForTheseExportOptions(); // from the exporting point of view we should always have been using png options // set them to the png options for the export part if (pNewFilter) pNewFilter->SetExportOptions(pExportOptions); // gets the real export options that the prevdlg has set up for us BmapPrevDlg::m_pExportOptions = NULL; // take responsibility for this data } else { // the animation export didn't bring up the dlg so never set BmapPrevDlg::m_pExportOptions // so continue with these options pExportOptions = (BitmapExportOptions*)pMakeBmpExportOptions; } SetExportOptions(pExportOptions); if (!ok) { SetExportOptions(NULL); // deletes the filter ptr and nulls it delete pExportOptions; return FALSE; // if cancelled } //////////////// SMFIX pExportOptions->MarkValid(); SetDepthToRender(pExportOptions->GetDepth()); // Set up device context and render region for this export. // This will show a progress hourglass for the objects being rendered // THis will now also write the data out to file via our ExportRenderNodes function if (!PrepareToExport(pSpread, pExportOptions->GetDepth(), pExportOptions->GetDPI(), pExportOptions->GetSelectionType(), pExportOptions->GetDither())) { pNewFilter->SetExportOptions(NULL); SetExportOptions(NULL); delete pExportOptions; CleanUpAfterExport(); return FALSE; } RenderInStrips = FALSE; if (!ExportRender(ExportRegion)) { pNewFilter->SetExportOptions(NULL); // deletes the filter ptr and nulls it SetExportOptions(NULL); delete pExportOptions; CleanUpAfterExport(); return FALSE; } // Now get the converted 32Bit BMP pTheBitmap = GetTheBitmap(pExportOptions); // if we`ve got a transparency index AND we`ve got a 32 Bit Render region with alpha channel info // then we can quickly do if(pExportOptions->GetDepth() <= 8 && pExportOptions->GetTransparencyIndex() != -1 && pTheBitmap) { // What we do now is to go throught the bitmap setting the relavent pixels to transparent // depending on the alpha channel info held in the 32 bit version. if(!ApplyTransparentColoursToBitmap(pTheBitmap,pExportOptions)) { pNewFilter->SetExportOptions(NULL); // deletes the filter ptr and nulls it return FALSE; } // Now make sure the bitmap knows that it has a transparent colour! pTheBitmap->SetTransparencyIndex(pExportOptions->GetTransparencyIndex()); } // Set pointer to the bitmap we have created *ppBitmap = pTheBitmap; pNewFilter->SetExportOptions(NULL); // deletes the filter ptr and nulls it SetExportOptions(NULL); delete pExportOptions; CleanUpAfterExport(); return *ppBitmap != NULL; //////////////// SMFIX }
/** This test will verify that left and right text alignment is swapped when the application language is set to a RightToLeft script, unless the alignment is set to be absolute. This will be done in 9 steps, drawing a four line text clockwise from topLeft, via topCenter, topRight, bottomRight, bottomCenter, bottomLeft, topLeft, topCenter, to topRight. Visual verification is required. */ TBool CCone7TestAppUi::TestTextDrawer_4L() { CCtlTestTextDrawer* testTextDrawer = new(ELeave) CCtlTestTextDrawer(); CleanupStack::PushL(testTextDrawer); testTextDrawer->ConstructL(); testTextDrawer->SetExtent(TPoint(20,20),TSize(600,200)); testTextDrawer->ActivateL(); testTextDrawer->DrawNow(); const TInt noOfLines = TCoeTextTypeAdaptor(KMultipleLineText).NumberOfLines(); TEST(noOfLines == 4); INFO_PRINTF2(_L("Number of lines in the text separated by new line character are : %d"), noOfLines); TOpenFontFaceAttrib openFontFaceAttrib; ((CFbsFont&)(testTextDrawer->FontUsed())).GetFaceAttrib(openFontFaceAttrib); TBuf<25> buf(openFontFaceAttrib.FullName()); INFO_PRINTF2(_L("CCtlTestTextDrawer : Typeface being used is %S"), &buf); CWsScreenDevice* screenDevice = iCoeEnv->ScreenDevice(); TSize sizeInPixels = screenDevice->SizeInPixels(); TSize sizeInTwips = screenDevice->SizeInTwips(); TInt xPixel = sizeInPixels.iWidth; TInt xTwips = sizeInTwips.iWidth; TInt yPixel = sizeInPixels.iHeight; TInt yTwips = sizeInTwips.iHeight; TInt KLineWidthsInPixels[4]; //Line width in pixels on H4 if(xPixel == 320 && xTwips == 4463 && yPixel == 240 && yTwips == 3041) { KLineWidthsInPixels[0] = 80; KLineWidthsInPixels[1] = 51; KLineWidthsInPixels[2] = 110; KLineWidthsInPixels[3] = 100; } //Line width in pixels on H6 QVGA else if(xPixel == 240 && xTwips == 3685 && yPixel == 320 && yTwips ==5056) { KLineWidthsInPixels[0] = 64; KLineWidthsInPixels[1] = 41; KLineWidthsInPixels[2] = 88; KLineWidthsInPixels[3] = 80; } //Line width in pixels on H6 VGA else if(xPixel == 480 && xTwips == 3685 && yPixel == 640 && yTwips ==5056) { KLineWidthsInPixels[0] = 128; KLineWidthsInPixels[1] = 81; KLineWidthsInPixels[2] = 176; KLineWidthsInPixels[3] = 160; } //Line width in pixels on emulator else if(xPixel == 640 && xTwips == 7620 && yPixel == 240 && yTwips == 2858) { KLineWidthsInPixels[0] = 80; KLineWidthsInPixels[1] = 51; KLineWidthsInPixels[2] = 110; KLineWidthsInPixels[3] = 100; } //Line width in pixels on NaviEngine else if(xPixel == 800 && xTwips == 9520 && yPixel == 480 && yTwips == 5712) { KLineWidthsInPixels[0] = 80; KLineWidthsInPixels[1] = 51; KLineWidthsInPixels[2] = 110; KLineWidthsInPixels[3] = 100; } //Line width in pixels on NaviEngine without integrated screen else if(xPixel == 640 && xTwips == 7616 && yPixel == 480 && yTwips == 5712) { KLineWidthsInPixels[0] = 80; KLineWidthsInPixels[1] = 51; KLineWidthsInPixels[2] = 110; KLineWidthsInPixels[3] = 100; } else { INFO_PRINTF1(_L("This might be a new hardware, need to calculate line widths in pixels again.")); INFO_PRINTF5(_L("xPixel=%d, xTwips=%d, yPixel=%d, yTwips=%d"),xPixel,xTwips,yPixel,yTwips); CleanupStack::PopAndDestroy(testTextDrawer); return EFalse; } TInt widthInPixels = 0; for (TInt line = 0; line < noOfLines; line++) { testTextDrawer->WidthOfText(line, widthInPixels); TInt testWidth = KLineWidthsInPixels[line]; // Allow a tolerance of 1 pixel difference less than KLineWidthsInPixels TEST(Rng(testWidth-1, widthInPixels, testWidth)); INFO_PRINTF3(_L("Width for line %d in pixels : %d"), line, widthInPixels); } for(TInt testIndex = 0; testIndex <= 8; testIndex++) { testTextDrawer->TestTextDrawer(testIndex, ETrue); User::After( TTimeIntervalMicroSeconds32(1000000) ); } CleanupStack::PopAndDestroy(testTextDrawer); return ETrue; }