//------------------------------------------------------------------------------ void MeanGridSeg::CalcMeans(const ds::Array2D<nat32> & seg,ds::Array<Mean> & mean) { // Go through and zero out the means... for (nat32 i=0;i<mean.Size();i++) { mean[i].samples = 0; mean[i].x = 0.0; mean[i].y = 0.0; mean[i].l = 0.0; mean[i].u = 0.0; mean[i].v = 0.0; } // Iterate through all pixels and sum in their affect to the means... for (nat32 y=0;y<seg.Height();y++) { for (nat32 x=0;x<seg.Width();x++) { nat32 i = seg.Get(x,y); const bs::ColourLuv & col = image.Get(x,y); mean[i].samples += 1; real32 weight = 1.0/real32(mean[i].samples); mean[i].x += weight * (real32(x)-mean[i].x); mean[i].y += weight * (real32(y)-mean[i].y); mean[i].l += weight * (col.l-mean[i].l); mean[i].u += weight * (col.u-mean[i].u); mean[i].v += weight * (col.v-mean[i].v); } } }
real32 Progress::Prog() { real32 ret = 0.0; real32 fact = 1.0; for (nat32 i=0;i<=depth;i++) { if (data[i].second!=0) { ret += fact * real32(data[i].first)/real32(data[i].second); fact *= 1.0/real32(data[i].second); } } return ret; }
void ScalePair::UpdatePair(gui::Base * obj,gui::Event * event) { str::String fn; if (cyclops.App().LoadFileDialog("Select Camera Pair File","*.pcc",fn)) { cam::CameraPair pair; if (pair.Load(fn)==false) { cyclops.App().MessageDialog(gui::App::MsgErr,"Failed to load camera pair file"); } else { // Get the factor... real32 factor = newHeight->Get().ToReal32(); if (factor>1.0) factor /= real32(leftImage.Size(1)); LogDebug("Scaling .pcc by a factor of " << factor); // Apply to both sides... pair.ScaleLeft(pair.leftDim[0]*factor,pair.leftDim[1]*factor); pair.ScaleRight(pair.rightDim[0]*factor,pair.rightDim[1]*factor); // Save back the file... str::String fn2; if (cyclops.App().SaveFileDialog("Save Camera Pair File...",fn2)) { if (!fn2.EndsWith(".pcc")) fn2 += ".pcc"; if (!pair.Save(fn2,true)) { cyclops.App().MessageDialog(gui::App::MsgErr,"Error saving back the file."); return; } } } } }
//------------------------------------------------------------------------------ EOS_FUNC void ForwardWarp(const svt::Field<bs::ColourRGB> & image,const svt::Field<real32> & disp,svt::Field<bs::ColourRGB> & out,real32 co,real32 t,const svt::Field<bit> * mask) { // Create a tempory depth map... (Actually a disparity map, higher is nearer.) svt::Var * temp = new svt::Var(image.GetVar()->GetCore()); temp->Setup2D(out.Size(0),out.Size(1)); real32 depthIni = -1.0; temp->Add("depth",depthIni); temp->Commit(); svt::Field<real32> depth; temp->ByName("depth",depth); // Set all pixels in out to be blue, incase there not written to... for (nat32 y=0;y<out.Size(1);y++) { for (nat32 x=0;x<out.Size(0);x++) { out.Get(x,y) = bs::ColourRGB(0.0,0.0,1.0); } } // Iterate the image and render each pixel, taking into account the depth map... for (nat32 y=0;y<image.Size(1);y++) { for (nat32 x=0;x<image.Size(0)-1;x++) { if ((mask==null<svt::Field<bit>*>())||(mask->Get(x,y)&&mask->Get(x+1,y))) { // Interpolate from this x to x+1, writting to any integers intercepted // along the way... real32 startX = x + t*disp.Get(x,y); real32 endX = x + 1.0 + t*disp.Get(x+1,y); real32 mult = 1.0/(endX-startX); if (math::Abs(endX-startX)<co) { int32 si = math::Max<int32>(0,math::RoundUp(int32(math::Min(startX,endX)))); int32 ei = math::Min<int32>(out.Size(0)-1,math::RoundDown(int32(math::Max(startX,endX)))); for (int32 i = si;i<=ei;i++) { real32 t = math::Clamp<real32>((real32(i)-startX)*mult,0.0,1.0); real32 d = math::Abs((1.0-t)*disp.Get(x,y) + t*disp.Get(x+1,y)); if (d>depth.Get(i,y)) { bs::ColourRGB colour; colour.r = (1.0-t)*image.Get(x,y).r + t*image.Get(x+1,y).r; colour.g = (1.0-t)*image.Get(x,y).g + t*image.Get(x+1,y).g; colour.b = (1.0-t)*image.Get(x,y).b + t*image.Get(x+1,y).b; out.Get(i,y) = colour; depth.Get(i,y) = d; } } } } } } // Clean up... delete temp; }
real32 WarpInc::RawScore() const { real32 ret = 0.0; nat32 retCount = 0; Node * targ = pixel; for (nat32 i=0;i<width*height;i++) { // If theres nothing in this node we add in an oclusion cost, otherwise we // have the cost of the top pixel plus all occluded pixels hiding under it... if (targ->count==false) continue; if (targ->next->head==null<Node*>()) { ++retCount; } else { Node * st = targ->next; // Colour difference cost... ret += math::Abs(st->colour.r-targ->colour.r) + math::Abs(st->colour.g-targ->colour.g) + math::Abs(st->colour.b-targ->colour.b); st = st->next; // Occlusion cost... while (st->head!=null<Node*>()) { ++retCount; st = st->next; } } ++targ; } return ret + real32(retCount)*occCost; }
void Frequency::Norm(const MessageClass & mc,void * obj) { real32 * targ = static_cast<real32*>(obj); real32 val = 0.0; for (nat32 i=0;i<mc.scale;i++) val += targ[i]; if (math::Equal(val,real32(0.0))) return; val = 1.0/val; for (nat32 i=0;i<mc.scale;i++) targ[i] *= val; }
void ScalePair::UpdateDim() { // Get factor... real32 factor = newHeight->Get().ToReal32(); if (factor>1.0) factor /= real32(rightImage.Size(1)); // Create dimension string... str::String s; s << "left = (" << nat32(leftImage.Size(0)*factor) << "," << nat32(leftImage.Size(1)*factor); s << "); right = (" << nat32(rightImage.Size(0)*factor) << "," << nat32(rightImage.Size(1)*factor) << ")"; // Display... newDim->Set(s); }
void ScalePair::SaveRight(gui::Base * obj,gui::Event * event) { // Ask the user for a filename... str::String fn(""); if (cyclops.App().SaveFileDialog("Save Scaled Right Image",fn)) { if (!(fn.EndsWith(".bmp")||fn.EndsWith(".jpg")||fn.EndsWith(".tga")||fn.EndsWith(".png"))) fn << ".bmp"; // Calculate the scale factor and the new image size - kept seperate as we // obviously need it to be correct... real32 factor = newHeight->Get().ToReal32(); if (factor>1.0) factor /= real32(rightImage.Size(1)); int32 width = int32(factor*rightImage.Size(0)); int32 height = int32(factor*rightImage.Size(1)); // Create a data structure to contain it... svt::Var civ(cyclops.Core()); civ.Setup2D(width,height); bs::ColourRGB iniRGB(0.0,0.0,0.0); civ.Add("rgb",iniRGB); civ.Commit(false); svt::Field<bs::ColourRGB> ci(&civ,"rgb"); // Create an input and output mask, fill in the input mask... svt::Var inMaskVar(cyclops.Core()); inMaskVar.Setup2D(rightImg.Size(0),rightImg.Size(1)); bit maskIni = true; inMaskVar.Add("mask",maskIni); inMaskVar.Commit(); svt::Field<bit> inMask(&inMaskVar,"mask"); svt::Var outMaskVar(cyclops.Core()); outMaskVar.Setup2D(width,height); outMaskVar.Add("mask",maskIni); outMaskVar.Commit(); svt::Field<bit> outMask(&outMaskVar,"mask"); for (nat32 y=0;y<rightImg.Size(1);y++) { for (nat32 x=0;x<rightImg.Size(0);x++) { if (math::Equal(rightImg.Get(x,y).r,real32(1.0))&& math::Equal(rightImg.Get(x,y).g,real32(0.0))&& math::Equal(rightImg.Get(x,y).b,real32(1.0))) inMask.Get(x,y) = false; } } // Fill data structure... filter::ScaleExtend(rightImg,inMask,ci,outMask,factor); // Use the output mask to pink-out as needed... for (int32 y=0;y<height;y++) { for (int32 x=0;x<width;x++) { if (outMask.Get(x,y)==false) ci.Get(x,y) = bs::ColourRGB(1.0,0.0,1.0); } } // Save it... cstr ts = fn.ToStr(); if (!filter::SaveImage(ci,ts,true)) { cyclops.App().MessageDialog(gui::App::MsgErr,"Error saving scaled image."); } mem::Free(ts); } }
real32 Icosphere::SubToAng(nat32 subdivs) { real32 baseAng = math::InvCos((1.0+math::Sqrt(5.0))/(5+math::Sqrt(5.0))); return baseAng/real32(subdivs+1); }
if (lastDllHandle != INVALID_HANDLE_VALUE) { } // note(caf): we check the _modified_ date because silly me, creation date // is literally the time the file with that name first existed GetFileTime(lastDllHandle, 0, 0, &dll->lastCreationDate); CloseHandle(lastDllHandle); } } internal void win32_UnloadGmbDll(win32_gmbdll *dll) { assert(dll->Handle); FreeLibrary(dll->Handle); } internal const int bitDepth = 32; internal const real32 targetMS = real32(1000.0 / 60.0); global bool32 running = true; global WIN32SCREENBUFFER screenBuffer = {0}; int WinMain(HINSTANCE instance, HINSTANCE previnstance, LPSTR cmdline, int cmdshow) { win32_gmbdll gmbDLL; win32_InitGmbDll(&gmbDLL); WNDCLASS tclass = {0}; tclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; tclass.lpfnWndProc = &gmbWindowProc; tclass.hInstance = 0; tclass.lpszClassName = "gmb_class_lol"; tclass.hCursor = LoadCursorA(0, IDC_ARROW); ATOM windowClass = RegisterClassA(&tclass); if (windowClass == 0) {
real32 WarpInc::ScoreOcc() const { return real32(occCount)*occCost; }
real32 WarpInc::Score() const { return diffSum + real32(occCount)*occCost; }