void f() { Used(); Used(1); Used(1, 1); Unused(); // expected-warning {{expression result unused}} Unused(1); // expected-warning {{expression result unused}} Unused(1, 1); // expected-warning {{expression result unused}} }
/// Print matrix to stream ostream & Print (ostream & ost) const { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) if (Used (i, j)) ost << setw(8) << (*this)(i,j) << " "; else if (Used (j,i)) ost << setw(8) << "sym" << " "; else ost << setw(8) << 0; ost << endl; } return ost; }
int llSplitAt::Exec(void) { if (!llTriMod::Exec()) return 0; if (!Used("-x") && !Used("-y")) { _llLogger()->WriteNextLine(-LOG_ERROR, "%s: either -x or -y has to be defined", command_name); return 0; } if (Used("-x")) { triangles->DivideAt(true, x, map); } if (Used("-y")) { triangles->DivideAt(false, y, map); } _llLogger()->WriteNextLine(LOG_COMMAND, "%s: done", command_name); return 1; }
unsigned alpha1(UInt d,UInt sx,UInt sy) const // d in [0,sx] { Used(sy); double t=double(d)/sx; if( t>b ) return 0; return Map( Sq(b-t)/tau2 ); }
QString ManualCaptchaSolver::Solve(const QString& base64) { emit Used(); emit ChangedSize(++Size); SingleCaptchaWidget *w = new SingleCaptchaWidget(); w->setParent(Widget); w->SetCaptcha(base64,QString::number(IdCounter)); connect(w,SIGNAL(Done(QString,QString,bool)),this,SIGNAL(Done(QString,QString,bool))); Layout->addWidget(w); return QString::number(IdCounter++); }
int llSetGrid::Exec(void) { if (!llSet::Exec()) return 0; float minab = 0; if (_llUtils()->GetValueF("_mindistance")) minab = (float)(*_llUtils()->GetValueF("_mindistance")); if (!Used("-stepx")) stepx = -1; if (!Used("-stepy")) stepy = -1; for (float x=floor(_llUtils()->x00/gridx)*gridx; x<=(_llUtils()->x11+1); x+=gridx) { for (float y=floor(_llUtils()->y00/gridy)*gridy; y<=(_llUtils()->y11+1); y+=gridy) { float x1=x, y1=y; if (x >= _llUtils()->x11) x1 = _llUtils()->x11; if (y >= _llUtils()->y11) y1 = _llUtils()->y11; if (map->IsInMap(x1,y1) && points->IsNotTooClose(x1,y1,minab)) { points->AddPoint(x1, y1, map->GetZ(x1,y1)); //gen_npoints++; } if (stepx > 0) { for (float xx=x1; xx<(x1+gridx); xx+=stepx) { if (map->IsInMap(xx,y1) && points->IsNotTooClose(xx,y1,minab)) { points->AddPoint(xx, y1, map->GetZ(xx,y1)); } } } if (stepy > 0) { for (float yy=y1; yy<(y1+gridy); yy+=stepy) { if (map->IsInMap(x1,yy) && points->IsNotTooClose(x1,yy,minab)) { points->AddPoint(x1, yy, map->GetZ(x1,yy)); } } } } } return 1; }
int CInstrumentManager::GetFreeSequenceIndex(inst_type_t InstType, int Type, CSeqInstrument *pInst) const { // moved from CFamiTrackerDoc std::vector<bool> Used(CSequenceCollection::MAX_SEQUENCES, false); for (int i = 0; i < MAX_INSTRUMENTS; i++) if (GetInstrumentType(i) == InstType) { // // // auto pInstrument = std::static_pointer_cast<CSeqInstrument>(GetInstrument(i)); if (pInstrument->GetSeqEnable(Type) && (pInst && pInst->GetSequence(Type)->GetItemCount() || pInst != pInstrument.get())) Used[pInstrument->GetSeqIndex(Type)] = true; } for (int i = 0; i < CSequenceCollection::MAX_SEQUENCES; ++i) if (!Used[i]) { const CSequence *pSeq = GetSequence(InstType, Type, i); if (!pSeq || !pSeq->GetItemCount()) return i; } return -1; }
int llMapWorker::Exec(void) { llWorker::Exec(); if (!Used("-map")) mapname = (char *)"_heightmap"; //get the corresponding map from the global map container map = _llMapList()->GetMap(mapname); if (!map) { _llLogger()->WriteNextLine(-LOG_ERROR, "%s: map [%s] not found", command_name, mapname); return 0; } triangles = _llMapList()->GetTriangleList(mapname); points = _llMapList()->GetPointList(mapname); polygons = _llMapList()->GetPolygonList(mapname); return 1; }
unsigned alpha0(UInt d,UInt sx,UInt sy) const // d in [0,sx] { Used(sy); double t=double(d)/sx; if( t<a ) { return Map( M-Sq(t)/tau ); } if( t<b ) { return Map( 1-Sq(t+a)/tau2 ); } if( t<1-a ) { return Map( S-t ); } return Map( Sq(b+1-t)/tau2 ); }
virtual void draw(DrawBuf buf,bool drag_active) const { Used(drag_active); CommonDrawArt art(buf); art.erase(+cfg.back); AlignX align_x[4]={AlignX_Left,AlignX_Center,AlignX_Right,AlignX_Given}; AlignY align_y[4]={AlignY_Top,AlignY_Center,AlignY_Bottom,AlignY_Given}; for(int i=0; i<4 ;i++) for(int j=0; j<4 ;j++) { art.block(pane[i][j],+cfg.field); TextPlace place(align_x[i],align_y[j]); place.x=base.x; place.y=base.y; cfg.font->text(buf,pane[i][j],place,StrLen(text,len),+cfg.text); } }
int llSetHeight::Exec(void) { if (!llMapWorker::Exec()) return 0; llAlgCollection *algs = NULL; if (Used("-alg")) { algs = _llAlgList()->GetAlgCollection(alg_list); if (!algs) { _llLogger()->WriteNextLine(-LOG_FATAL, "%s: alg collection '%s' not found", command_name, alg_list); return 0; } } if (usegameunits) zmin /= map->GetZScale(); //convert to heightmap units int x1 = (int) map->GetRawX(_llUtils()->x00); int x2 = (int) map->GetRawX(_llUtils()->x11); int y1 = (int) map->GetRawY(_llUtils()->y00); int y2 = (int) map->GetRawY(_llUtils()->y11); for (int x=x1; x<=x2; x+=1) { for (int y=y1; y<=y2; y+=1) { double alg = 0.0; if (algs) { alg = algs->GetValue(map->GetCoordX(x), map->GetCoordY(y)); } if (min && map->GetElementRaw(x, y) < zmin) map->SetElementRaw(x, y, zmin + alg); else if (max && map->GetElementRaw(x, y) > zmin) map->SetElementRaw(x, y, zmin + alg); else if (!min && !max) map->SetElementRaw(x, y, zmin + alg); } } return 1; }
int llSetAtGridLine::Exec(void) { if (!llSet::Exec()) return 0; float minab = 0; if (_llUtils()->GetValueF("_mindistance")) minab = (float)(*_llUtils()->GetValueF("_mindistance")); int zused = 0; if (!Used("-zmin")) zused = 1; int gb_points=0; for (float x=floor(_llUtils()->x00/gridx)*gridx; x<=(_llUtils()->x11)-gridx; x+=gridx) { for (float y=floor(_llUtils()->y00/gridy)*gridy; y<=(_llUtils()->y11)-gridy; y+=gridy) { //List of segments float segstart[1000]; float segend[1000]; int segaktive[1000]; int segpointer=0; //fill the first segment segstart[segpointer] = x; segend[segpointer] = x + gridx; segaktive[segpointer] = 1; segpointer++; for (int i=0; i<segpointer; i++) { //is segment large enough? if (segend[i]-segstart[i]>2*minab && segaktive[i]) { float mymax = -1; float myx = segstart[i]+minab; float z = map->GetZ(segstart[i] + minab, y); float slope = (map->GetZ(segend[i]-minab,y) -z ) / (segend[i] - segstart[i] - 2*minab); for (float x1 = segstart[i]+minab ;x1 < segend[i]-minab; x1++) { float walldiff = (z + slope * (x1 - (segstart[i]+minab))) - map->GetZ(x1,y); if (walldiff > max && walldiff>mymax && (map->GetZ(x1,y)>zmin || zused)) { mymax = walldiff; myx = x1; } } if (mymax>0) { //Split segment points->AddPoint(myx, y, map->GetZ(myx,y)); //gen_npoints++; gb_points++; segaktive[i]=0; segstart[segpointer] = segstart[i]; segend[segpointer] = myx; segaktive[segpointer] = 1; segpointer++; segstart[segpointer] = myx; segend[segpointer] = segend[i]; segaktive[segpointer] = 1; segpointer++; i = 0; } else segaktive[i] = 0; } else segaktive[i] = 0; } segpointer=0; //fill the first segment segstart[segpointer] = y; segend[segpointer] = y + gridy; segaktive[segpointer] = 1; segpointer++; for (int i=0; i<segpointer; i++) { //is segment large enough? if (segend[i]-segstart[i]>2*minab && segaktive[i]) { float mymax = -1; float myy = segstart[i] + minab; float z = map->GetZ(x,segstart[i]+minab); float slope = (map->GetZ(x,segend[i]-minab) -z ) / (segend[i] - segstart[i] - 2*minab); for (float y1 = segstart[i]+minab ;y1 < segend[i]-minab; y1++) { float walldiff = (z + slope * (y1 - (segstart[i]+minab))) - map->GetZ(x,y1); if (walldiff > max && walldiff>mymax && (map->GetZ(x,y1)>zmin || zused)) { mymax = walldiff; myy = y1; } } if (mymax>0) { //Split segment points->AddPoint(x, myy, map->GetZ(x,myy)); //gen_npoints++; gb_points++; segaktive[i] = 0; segstart[segpointer] = segstart[i]; segend[segpointer] = myy; segaktive[segpointer] = 1; segpointer++; segstart[segpointer] = myy; segend[segpointer] = segend[i]; segaktive[segpointer] = 1; segpointer++; i = 0; } else segaktive[i] = 0; } else segaktive[i] = 0; } #if 0 if (points->GetMinDistance(x1,y1) > minab) { points->AddPoint(x1,y1,heightmap->GetZ(x1,y1)); gen_npoints++; } #endif } } _llLogger()->WriteNextLine(-LOG_INFO, "%i break vertices set", gb_points); return 1; }
void Life::react_Key(VKey vkey,KeyMod kmod) { Used(kmod); switch( vkey ) { case VKey_Space : { running=!running; if( running && has_focus ) setStart(); } break; case VKey_NumPlus : { divider.dec(); } break; case VKey_NumMinus : { divider.inc(); } break; case VKey_Enter : { if( !running ) { if( sec_scope.nextScope_skip() ) { speed=Diff(step_number,map.getStepNumber()); } map.step(); redraw(); } } break; case VKey_F5 : { map.reset(); running=false; redraw(); } break; #if 0 case VKey_F10 : { if( kmod&KeyMod_Alt ) { Printf(Exception,"test"); } } break; #endif } }
void ComparableModels::CreateUsingOctree() { /* Determines the matching points, but nothing about their relative distance. */ /* Outputs: UsedWorldPoints, MatchingModelPoints: The points in these two files are correspondences */ assert(World.NumPoints() >= 4); //there must be enough points to determine a frustrum Model.setPointIndices(); World.setPointIndices(); ModelNumber = 0; //cull the world points by seeing which world points are in the visual hull (visual frustrum) of the model vgl_box_3d<double> ModelBox = Model.GetBoundingBox(); std::vector<vgl_point_3d<double> > WorldOPCoords = GetOPCoords(World.getPoints()); std::vector<unsigned int> WorldIndicesInsideFrustrum = geom::IndicesInsideFrustrum(ModelBox, WorldOPCoords, Scanner.ScanParams.getLocation()); this->MissPoints = 0; unsigned int ValidModel = 0; unsigned int NumFrustrumPoints = WorldIndicesInsideFrustrum.size(); std::clog << "There are " << NumFrustrumPoints << " points inside the viewing frustrum." << std::endl; boost::progress_display* show_progress = NULL; if(ShowProgress_) { //std::clog << "Comparable models showing progress." << std::endl; //std::clog << "Setup progressbar with " << NumFrustrumPoints << " points." << std::endl; show_progress = new boost::progress_display(NumFrustrumPoints); } else { //std::clog << "Comparable models not showing progress." << std::endl; } //#pragma omp parallel for shared(ModelPoints, WorldPoints, InvalidModel, ValidModel) private(WorldPoint, dir, LP, bIntersect, ModelPoint) std::vector<unsigned int> TempUsedWorldPoints(NumFrustrumPoints); std::vector<OrientedPoint> TempMatchingModelPoints(NumFrustrumPoints); std::vector<bool> Used(NumFrustrumPoints, false); #pragma omp parallel for for(unsigned int i = 0; i < NumFrustrumPoints; i++) { if(ShowProgress_) ++(*show_progress);//this should be atomic vgl_point_3d<double> WorldPoint; vgl_vector_3d<double> dir; LidarPoint LP; bool bIntersect; WorldPoint = World.getCoord(WorldIndicesInsideFrustrum[i]); dir = WorldPoint - Scanner.ScanParams.getLocation(); bIntersect = Scanner.AcquirePoint(Model, dir, LP); if(!bIntersect) { this->MissPoints++; //this should be atomic continue; } else { if(!LP.getValid()) { std::cout << "The intersection is not valid!" << std::endl; } if(LP.getCoord() == Scanner.ScanParams.getLocation()) { std::cout << "Intersection is at the scanner?!" << std::endl; } ValidModel++; //this should be atomic TempUsedWorldPoints[i] = WorldIndicesInsideFrustrum[i]; //save world point index TempMatchingModelPoints[i] = OrientedPoint(LP.getCoord()); //save model point (could be a point not originally on the model if triangles were intersected) Used[i] = true; } } std::clog << "Miss points: " << MissPoints << " ValidModel: " << ValidModel << std::endl; MatchingModelPoints.clear(); UsedWorldPoints.clear(); //go through TempMatchingModelPoints and TempUsedWorldPoints and put valid points into the non-temp versions unsigned int usedcount = 0; for(unsigned int i = 0; i < NumFrustrumPoints; i++) { if(Used[i] == true) { usedcount++; MatchingModelPoints.push_back(TempMatchingModelPoints[i]); UsedWorldPoints.push_back(TempUsedWorldPoints[i]); } } //std::clog << "Matching model points: " << MatchingModelPoints.size() << " UsedWorldPoints: " << UsedWorldPoints.size() << std::endl; //std::clog << "usedcount: " << usedcount << " ValidModel: " << ValidModel << std::endl; std::clog << "There are " << usedcount << " points that match for consistency evaluation." << std::endl; this->NumPoints = ValidModel; }
int llScaleMap::Exec(void) { if (!llMapWorker::Exec()) return 0; if (!Used("-name")) { targetname = new char[strlen(mapname)+5]; sprintf_s(targetname, strlen(mapname)+5, "%s_tmp", mapname); } if (!Used("-factor") && (!Used("-sizeX") || !Used("-sizeY"))) { _llLogger()->WriteNextLine(-LOG_ERROR, "%s: -sizeX and -sizeY must be used if no factor is given", command_name); return 0; } llMap *newmap = _llMapList()->GetMap(targetname); if (newmap) { _llLogger()->WriteNextLine(-LOG_ERROR, "%s: map %s existing", command_name, targetname); return 0; } int widthx = map->GetWidthX(); int widthy = map->GetWidthY(); int newwidthx = (int)sizex; int newwidthy = (int)sizey; if (Used("-factor")) { if (map->IsUneven()) { newwidthx = int(float(map->GetWidthX()-1)*factor)+1; newwidthy = int(float(map->GetWidthY()-1)*factor)+1; } else { newwidthx = int(float(map->GetWidthX())*factor); newwidthy = int(float(map->GetWidthY())*factor); } _llLogger()->WriteNextLine(-LOG_INFO, "%s: new width (%i, %i)", command_name, newwidthx, newwidthx); } float defaultheight = map->GetDefaultHeight(); int makeshort = map->GetShort(); newmap = new llMap(newwidthx, newwidthy, makeshort, defaultheight); const int max_components = 4; int n = 1; if (map->IsColorMap() || Used("-rgb")) n = 4; if (std::max(widthx, widthy) > RESAMPLER_MAX_DIMENSION) { _llLogger()->WriteNextLine(-LOG_ERROR, "%s: size too large (>RESAMPLER_MAX_DIMENSION)", command_name); return 0; } const float filter_scale = 1.0f;//.75f; // Partial gamma correction looks better on mips. Set to 1.0 to disable gamma correction. //const float source_gamma = 1.75f; float srgb_to_linear[256]; for (unsigned int i = 0; i < 256; i++) srgb_to_linear[i] = (float)pow(float(i) * 1.0f/255.0f, source_gamma); const int linear_to_srgb_table_size = 4096; unsigned char linear_to_srgb[linear_to_srgb_table_size]; const float inv_linear_to_srgb_table_size = 1.0f / linear_to_srgb_table_size; const float inv_source_gamma = 1.0f / source_gamma; for (int i = 0; i < linear_to_srgb_table_size; ++i) { int k = (int)(255.0f * pow(i * inv_linear_to_srgb_table_size, inv_source_gamma) + .5f); if (k < 0) k = 0; else if (k > 255) k = 255; linear_to_srgb[i] = (unsigned char)k; } Resampler* resamplers[max_components]; std::vector<float> samples[max_components]; float min = 1.0, max = 0.0; if (n==4) { min = 0.0; max = 1.0; } // Now create a Resampler instance for each component to process. The first instance will create new contributor tables, which are shared by the resamplers // used for the other components (a memory and slight cache efficiency optimization). resamplers[0] = new Resampler(widthx, widthy, newwidthx, newwidthy, Resampler::BOUNDARY_CLAMP, min, max, pFilter, NULL, NULL, filter_scale, filter_scale); samples[0].resize(widthx); for (int i = 1; i < n; i++) { resamplers[i] = new Resampler(widthx, widthy, newwidthx, newwidthy, Resampler::BOUNDARY_CLAMP, min, max, pFilter, resamplers[0]->get_clist_x(), resamplers[0]->get_clist_y(), filter_scale, filter_scale); samples[i].resize(widthx); } if (resamplers[0]->status() == 2) { _llLogger()->WriteNextLine(-LOG_ERROR, "%s: Bad filter '%s'", command_name, pFilter); return 0; } int running_y = 0; for (int yy=0; yy<widthy; yy++) { for (int xx=0; xx<widthx; xx++) { if (n==1) samples[0][xx] = map->GetElementRaw(xx, yy); else { unsigned char byte1; unsigned char byte2; unsigned char byte3; unsigned char byte4; map->GetTupel(xx, yy, &byte1, &byte2, &byte3, &byte4); samples[0][xx] = srgb_to_linear[byte1]; samples[1][xx] = srgb_to_linear[byte2]; samples[2][xx] = srgb_to_linear[byte3]; samples[3][xx] = srgb_to_linear[byte4]; } } for (int c=0; c<n; c++) { if (!resamplers[c]->put_line(&samples[c][0])) { _llLogger()->WriteNextLine(-LOG_FATAL, "%s: Out of memory", command_name); return 0; } } int do_loop = 1; while (do_loop) { int c; const float *pOutput_samples[4]; for (c=0; c<n; c++) { pOutput_samples[c] = resamplers[c]->get_line(); if (!pOutput_samples[c]) do_loop = 0; } if (do_loop) { for (int xx=0; xx<newwidthx; xx++) { if (n == 1) newmap->SetElementRaw(xx, running_y, pOutput_samples[0][xx]); else { int j = (int)(linear_to_srgb_table_size * pOutput_samples[0][xx] + .5f); if (j < 0) j = 0; else if (j >= linear_to_srgb_table_size) j = linear_to_srgb_table_size - 1; unsigned int byte1 = (unsigned int)(linear_to_srgb[j]); j = (int)(linear_to_srgb_table_size * pOutput_samples[1][xx] + .5f); if (j < 0) j = 0; else if (j >= linear_to_srgb_table_size) j = linear_to_srgb_table_size - 1; unsigned int byte2 = (unsigned int)(linear_to_srgb[j]); j = (int)(linear_to_srgb_table_size * pOutput_samples[2][xx] + .5f); if (j < 0) j = 0; else if (j >= linear_to_srgb_table_size) j = linear_to_srgb_table_size - 1; unsigned int byte3 = (unsigned int)(linear_to_srgb[j]); j = (int)(linear_to_srgb_table_size * pOutput_samples[3][xx] + .5f); if (j < 0) j = 0; else if (j >= linear_to_srgb_table_size) j = linear_to_srgb_table_size - 1; unsigned int byte4 = (unsigned int)(linear_to_srgb[j]); newmap->SetTupel(xx, running_y, byte1, byte2, byte3, byte4); } } running_y++; if (running_y == newwidthy) break; } } } newmap->SetCoordSystem(map->GetX1(), map->GetY1(), map->GetX2(), map->GetY2(), map->GetZScale()); llPointList * points = _llMapList()->GetPointList(mapname); llTriangleList * triangles = _llMapList()->GetTriangleList(mapname); llLineList * lines = _llMapList()->GetLineList(mapname); llPolygonList * polygons = _llMapList()->GetPolygonList(mapname); if (Used("-name")) { _llMapList()->AddMap(targetname, newmap, points, triangles, polygons, lines); } else { delete (map); _llMapList()->ExchangeMap(mapname, newmap); } return 1; }
int llExportMap::Init(void) { if (!llWorker::Init()) return 0; if (!Used("-mapname")) mapname = "_heightmap"; if (!Used("-filename")) filename = "world.bmp"; if (!Used("-depth")) bits = 24; llMap * map = _llMapList()->GetMap(mapname); if (!map) { _llLogger()->WriteNextLine(-LOG_ERROR,"%s: map '%s' not found", command_name, mapname); return 0; } FILE *fptr; if (fopen_s(&fptr, filename,"wb")) { _llLogger()->WriteNextLine(-LOG_ERROR,"Unable to open BMP file '%s'\n", filename); return 0; } int x1 = map->GetRawX(_llUtils()->x00); int y1 = map->GetRawY(_llUtils()->y00); int x2 = map->GetRawX(_llUtils()->x11); int y2 = map->GetRawY(_llUtils()->y11); INFOHEADER infoheader; infoheader.width = x2-x1+1; infoheader.height = y2-y1+1; infoheader.compression=0; infoheader.size = 40; infoheader.planes = 1; /* Number of colour planes */ int bytesPerLine; if (bits == 24) infoheader.bits = 24; /* Bits per pixel */ else infoheader.bits = 32; if (bits == 24) { bytesPerLine = infoheader.width * 3; /* (for 24 bit images) */ /* round up to a dword boundary */ //Thanks to //http://www.siggraph.org/education/materials/HyperVis/asp_data/compimag/bmpfile.htm //for the hint if (bytesPerLine & 0x0003) { bytesPerLine |= 0x0003; ++bytesPerLine; } } else bytesPerLine = infoheader.width * 4; infoheader.imagesize = (long)bytesPerLine*infoheader.height; /* Image size in bytes */ infoheader.xresolution=100; infoheader.yresolution=100; /* Pixels per meter */ infoheader.ncolours=0; /* Number of colours */ infoheader.importantcolours; /* Important colours */ HEADER header; header.type='M'*256+'B'; header.size = 14 + 40 + infoheader.imagesize; header.reserved1 = header.reserved2 = 0; WriteUShort(fptr, header.type, 0); WriteUInt (fptr, header.size, 0); WriteUShort(fptr, header.reserved1, 0); WriteUShort(fptr, header.reserved2, 0); header.offset = 14+40; WriteUInt(fptr, header.offset, 0); /* Read and check the information header */ if (fwrite(&infoheader, sizeof(INFOHEADER), 1, fptr) != 1) { _llLogger()->WriteNextLine(-LOG_ERROR,"Failed to write BMP info header"); return 0; } for (int y=y2; y>=y1; y--) { int my_bytesPerLine = bytesPerLine; for (int x=x2; x>=x1; x--) { unsigned char byte1; unsigned char byte2; unsigned char byte3; unsigned char byte4; if (map->GetTupel(x, y, &byte1, &byte2, &byte3, &byte4)) { if (bits == 24) { my_bytesPerLine -= 3; fwrite(&byte1, 1, 1, fptr); //blue fwrite(&byte2, 1, 1, fptr); //green fwrite(&byte3, 1, 1, fptr); //red } else { fwrite(&byte1, 1, 1, fptr); //blue fwrite(&byte2, 1, 1, fptr); //green fwrite(&byte3, 1, 1, fptr); //red fwrite(&byte4, 1, 1, fptr); //alpha my_bytesPerLine -= 4; } } #if 0 float val = map->GetElementRaw(x,y); if (bits == 24) { my_bytesPerLine -= 3; unsigned int trunk1 = int(val) & 0xff; unsigned int trunk2 = (int(val) & 0xff00) >> 8; unsigned int trunk3 = (int(val) & 0xff0000) >> 16; fwrite(&trunk1, 1, 1, fptr); //blue fwrite(&trunk2, 1, 1, fptr); //green fwrite(&trunk3, 1, 1, fptr); //red } else { WriteUInt(fptr,unsigned int(val), 0); my_bytesPerLine -= 4; } #endif }
int llMakeDerivatives::Init(void) { if (!llWorker::Init()) return 0; if (!Used("-source")) sourcename = "_heightmap"; llMap *oldmap = _llMapList()->GetMap(sourcename); if (!oldmap) { _llLogger()->WriteNextLine(-LOG_ERROR,"%s: map %s not found", command_name, sourcename); return 0; } unsigned int widthx = oldmap->GetWidthX(); unsigned int widthy = oldmap->GetWidthY(); //Filtered map shares the points, etc with its master llPointList * points = _llMapList()->GetPointList(sourcename); llTriangleList * triangles = _llMapList()->GetTriangleList(sourcename); llPolygonList * polygons = _llMapList()->GetPolygonList(sourcename); char * namex1 = new char[strlen(sourcename)+5]; sprintf_s(namex1, strlen(sourcename)+5, "%s_d1x", sourcename); llMap *mapx1 = _llMapList()->GetMap(namex1); if (mapx1) { _llLogger()->WriteNextLine(-LOG_WARNING,"%s: derivative map '%s' exists, going to delete it", command_name, namex1); _llMapList()->DeleteMap(namex1); } char * namey1 = new char[strlen(sourcename)+5]; sprintf_s(namey1, strlen(sourcename)+5, "%s_d1y", sourcename); llMap *mapy1 = _llMapList()->GetMap(namey1); if (mapy1) { _llLogger()->WriteNextLine(-LOG_WARNING,"%s: derivative map '%s' exists, going to delete it", command_name, namey1); _llMapList()->DeleteMap(namey1); } char * namex2 = new char[strlen(sourcename)+5]; sprintf_s(namex2, strlen(sourcename)+5, "%s_d2x", sourcename); llMap *mapx2 = _llMapList()->GetMap(namex2); if (mapx2) { _llLogger()->WriteNextLine(-LOG_WARNING,"%s: derivative map '%s' exists, going to delete it", command_name, namex2); _llMapList()->DeleteMap(namex2); } char * namey2 = new char[strlen(sourcename)+5]; sprintf_s(namey2, strlen(sourcename)+5, "%s_d2y", sourcename); llMap *mapy2 = _llMapList()->GetMap(namey2); if (mapy2) { _llLogger()->WriteNextLine(-LOG_WARNING,"%s: derivative map '%s' exists, going to delete it", command_name, namey2); _llMapList()->DeleteMap(namey2); } llShortarray *data1x; llShortarray *data1y; llShortarray *data2x; llShortarray *data2y; ///float minheight = oldmap->GetDefaultHeight() + 1.0f; float minheight = -9999; int redone = 0; repeat: data1x = new llShortarray(widthx*widthy, makeshort); data1y = new llShortarray(widthx*widthy, makeshort); data2x = new llShortarray(widthx*widthy, makeshort); data2y = new llShortarray(widthx*widthy, makeshort); if (!data1x->SetElement(0,0.f) || !data1y->SetElement(0,0.f) || !data2x->SetElement(0,0.f) || !data2y->SetElement(0,0.f)) { //test bad alloc if (!makeshort) { makeshort = 1; redone = 1; _llLogger()->WriteNextLine(LOG_WARNING, "%s: memory allocation failed, I will try the 16bit version", command_name); delete data1x; delete data1y; delete data2x; delete data2y; data1x = data1y = data2x = data2y = NULL; goto repeat; } else { _llLogger()->WriteNextLine(-LOG_FATAL,"%s: out of memory", command_name); } } if (redone) { _llLogger()->AddToLine("... [OK]"); _llLogger()->Dump(); } float widthx_per_raw = oldmap->GetWidthXPerRaw(); float widthy_per_raw = oldmap->GetWidthYPerRaw(); x1max=0; for (unsigned int y=0; y<widthy; y++) { data1x->SetElement(y*widthx, (oldmap->GetElementRaw(1,y) - oldmap->GetElementRaw(0,y))); data1x->SetElement(y*widthx+widthx-1, (oldmap->GetElementRaw(widthx-1,y) - oldmap->GetElementRaw(widthx-2,y))); for (unsigned int x=1; x<widthx-1; x++) { if ((oldmap->GetElementRaw(x-1,y) > minheight && oldmap->GetElementRaw(x+1,y) > minheight)) { data1x->SetElement(x+y*widthx, (oldmap->GetElementRaw(x-1,y) - oldmap->GetElementRaw(x+1,y)) / (2.0f)); //cout << (oldmap->GetElementRaw(x-1,y) - oldmap->GetElementRaw(x+1,y)) / (2.0f) << endl; if (fabs(((*data1x)[x+y*widthx])) > x1max) x1max = fabs(((*data1x)[x+y*widthx])); } } } y1max=0; for (unsigned int x=0; x<widthx; x++) { data1y->SetElement(x, (oldmap->GetElementRaw(x,1) - oldmap->GetElementRaw(x,0))); data1y->SetElement(widthx+(widthy-1)*widthx, (oldmap->GetElementRaw(x,widthy-1) - oldmap->GetElementRaw(x,widthy-2))); for (unsigned int y=1; y<widthy-1; y++) { if ((oldmap->GetElementRaw(x,y-1) > minheight && oldmap->GetElementRaw(x,y+1) > minheight)) { data1y->SetElement(x+y*widthx, (oldmap->GetElementRaw(x,y-1) - oldmap->GetElementRaw(x,y+1)) / (2.0f)); if (fabs(((*data1y)[x+y*widthx])) > y1max) y1max = fabs(((*data1y)[x+y*widthx])); } } } mapx1 = new llMap(widthx, widthy, data1x , 0); mapx1->SetCoordSystem(oldmap->GetX1(), oldmap->GetY1(), oldmap->GetX2(), oldmap->GetY2(), oldmap->GetZScale()/widthx_per_raw); _llMapList()->AddMap(namex1, mapx1, points, triangles, polygons); mapy1 = new llMap(widthx, widthy, data1y , 0); mapy1->SetCoordSystem(oldmap->GetX1(), oldmap->GetY1(), oldmap->GetX2(), oldmap->GetY2(), oldmap->GetZScale()/widthy_per_raw); _llMapList()->AddMap(namey1, mapy1, points, triangles, polygons); x2max=0; for (unsigned int y=0; y<widthy; y++) { data1x->SetElement(y*widthx, mapx1->GetElementRaw(1,y) - mapx1->GetElementRaw(0,y)); data1x->SetElement(y*widthx+widthx-1, mapx1->GetElementRaw(widthx-1,y) - mapx1->GetElementRaw(widthx-2,y)); for (unsigned int x=1; x<widthx-1; x++) { if ((oldmap->GetElementRaw(x-1,y) > minheight && oldmap->GetElementRaw(x+1,y) > minheight)) { data2x->SetElement(x+y*widthx, (mapx1->GetElementRaw(x-1,y) - mapx1->GetElementRaw(x+1,y)) / 2.0f); if (fabs(((*data2x)[x+y*widthx])) > x2max) x1max = fabs(((*data2x)[x+y*widthx])); } } } y2max=0; for (unsigned int x=0; x<widthx; x++) { data1y->SetElement(x, mapy1->GetElementRaw(x,1) - mapy1->GetElementRaw(x,0)); data1y->SetElement(widthx+(widthy-1)*widthx, mapy1->GetElementRaw(x,widthy-1) - mapy1->GetElementRaw(x,widthy-2)); for (unsigned int y=1; y<widthy-1; y++) { if ((oldmap->GetElementRaw(x,y-1) > minheight && oldmap->GetElementRaw(x,y+1) > minheight)) { data2y->SetElement(x+y*widthx, (mapy1->GetElementRaw(x,y-1) - mapy1->GetElementRaw(x,y+1)) / 2.0f); if (fabs(((*data2y)[x+y*widthx])) > y2max) y1max = fabs(((*data2y)[x+y*widthx])); } } } data1x->Print(namex1, _llLogger()); data1y->Print(namey1, _llLogger()); data2x->Print(namex2, _llLogger()); data2y->Print(namey2, _llLogger()); mapx2 = new llMap(widthx, widthy, data2x, 0); mapx2->SetCoordSystem(oldmap->GetX1(), oldmap->GetY1(), oldmap->GetX2(), oldmap->GetY2(), oldmap->GetZScale()/widthx_per_raw); _llMapList()->AddMap(namex2, mapx2, points, triangles, polygons); mapy2 = new llMap(widthx, widthy, data2y, 0); mapy2->SetCoordSystem(oldmap->GetX1(), oldmap->GetY1(), oldmap->GetX2(), oldmap->GetY2(), oldmap->GetZScale()/widthy_per_raw); _llMapList()->AddMap(namey2, mapy2, points, triangles, polygons); return 1; }
int llFillColorMap::Exec(void) { if (!llMapWorker::Exec()) return 0; if (!map->IsColorMap()) { _llLogger()->WriteNextLine(-LOG_ERROR, "%s: map is no color map", command_name); return 0; } llAlgCollection *algs_blue = NULL; if (Used("-algblue")) { algs_blue = _llAlgList()->GetAlgCollection(alg_list_blue); if (!algs_blue) { _llLogger()->WriteNextLine(-LOG_ERROR, "%s: alg collection '%s' not found for blue channel", command_name, alg_list_blue); return 0; } algs_blue->UpdateMaps(); } llAlgCollection *algs_red = NULL; if (Used("-algred")) { algs_red = _llAlgList()->GetAlgCollection(alg_list_red); if (!algs_red) { _llLogger()->WriteNextLine(-LOG_ERROR, "%s: alg collection '%s' not found for red channel", command_name, alg_list_red); return 0; } algs_red->UpdateMaps(); } llAlgCollection *algs_green = NULL; if (Used("-alggreen")) { algs_green = _llAlgList()->GetAlgCollection(alg_list_green); if (!algs_green) { _llLogger()->WriteNextLine(-LOG_ERROR, "%s: alg collection '%s' not found for green channel", command_name, alg_list_green); return 0; } algs_green->UpdateMaps(); } llAlgCollection *algs_alpha = NULL; if (Used("-algalpha")) { algs_alpha = _llAlgList()->GetAlgCollection(alg_list_alpha); if (!algs_alpha) { _llLogger()->WriteNextLine(-LOG_ERROR, "%s: alg collection '%s' not found for alpha channel", command_name, alg_list_alpha); return 0; } algs_alpha->UpdateMaps(); } unsigned int widthx = map->GetWidthX(); unsigned int widthy = map->GetWidthY(); for (unsigned int x=0; x<widthx; x++) { for (unsigned int y=0; y<widthy; y++) { if (algs_blue) { double f_blue = 255. * algs_blue->GetValue(map->GetCoordX(x), map->GetCoordY(y)); if (f_blue > 255.) f_blue = 255.; unsigned char blue = (unsigned char)(f_blue); map->SetBlue(x, y, blue); } else map->SetBlue(x, y, 0); if (algs_red) { double f_red = 255. * algs_red->GetValue(map->GetCoordX(x), map->GetCoordY(y)); if (f_red > 255.) f_red = 255.; unsigned char red = (unsigned char)(f_red); map->SetRed(x, y, red); } else map->SetRed(x, y, 0); if (algs_green) { double f_green = 255. * algs_green->GetValue(map->GetCoordX(x), map->GetCoordY(y)); if (f_green > 255.) f_green = 255.; unsigned char green = (unsigned char)(f_green); map->SetGreen(x, y, green); } else map->SetGreen(x, y, 0); if (algs_alpha) { double f_alpha = 255. * algs_alpha->GetValue(map->GetCoordX(x), map->GetCoordY(y)); if (f_alpha > 255.) f_alpha = 255.; unsigned char alpha = (unsigned char)(f_alpha); map->SetAlpha(x, y, alpha); } else map->SetAlpha(x, y, 0); } } return 1; }
int llCreateNormalMap::Exec(void) { if (!llMapWorker::Exec()) return 0; if (!Used("-name")) { targetname = new char[strlen(mapname)+10]; sprintf_s(targetname, strlen(mapname)+10, "%s_normal", mapname); } int widthx = map->GetWidthX(); int widthy = map->GetWidthY(); llMap *newmap = _llMapList()->GetMap(targetname); int hasnewmap = 0; if (newmap) { _llLogger()->WriteNextLine(-LOG_WARNING,"%s: map %s existing, going to re-use it", command_name, targetname); //_llMapList()->DeleteMap(targetname); } else { hasnewmap = 1; newmap = new llMap(widthx-1, widthy-1, MAP_COLOR); newmap->SetEven(); newmap->SetCoordSystem(map->GetX1(), map->GetY1(), map->GetX2(), map->GetY2(), map->GetZScale()); } if (lodshadows) _llLogger()->WriteNextLine(-LOG_INFO, "Adding fake LOD shadows, 'north flip boost=%f'", northboost); else _llLogger()->WriteNextLine(-LOG_INFO, "Contrast z-boost=%f", boost); unsigned int x1 = map->GetRawX(_llUtils()->x00); unsigned int y1 = map->GetRawY(_llUtils()->y00); unsigned int x2 = map->GetRawX(_llUtils()->x11); unsigned int y2 = map->GetRawY(_llUtils()->y11); float st_array[3] = {0, 0, 0}; for (unsigned int y=y1; y<=y2; y++) { for (unsigned int x=x1; x<=x2; x++) { float height = map->GetZ(x,y); /*************************************/ if (lodshadows) { for (int v=0; v<3; v++) { //loop over direction vectors int directx = -1; int directy = 0; if (v==1) directx = 1; if (v==2) { directx = 0; directy = -1; } unsigned int cur_x = x + directx * resolution; unsigned int cur_y = y + directy * resolution; float slope = 0.f; int xx = int(cur_x)-int(x); int yy = int(cur_y)-int(y); int xxyy = xx + yy; if (xxyy<0) xxyy = -xxyy; while(xxyy < total_range && map->IsInMap(cur_x,cur_y) ) { float cur_slope = 0; if (v<2) cur_slope = directx * (map->GetZ(cur_x,cur_y)-height) / (map->GetWidthXPerRaw() * float(xx)); else cur_slope = directy * (map->GetZ(cur_x,cur_y)-height) / (map->GetWidthYPerRaw() * float(yy)); if (cur_slope > slope) slope = cur_slope; int stepsize = resolution * 8; if (xxyy < range) stepsize = resolution; else if (xxyy < 2*range) stepsize = resolution * 2; else if (xxyy < 4*range) stepsize = resolution * 4; cur_x += stepsize*directx; cur_y += stepsize*directy; xx = int(cur_x)-int(x); yy = int(cur_y)-int(y); xxyy = xx + yy; if (xxyy<0) xxyy = -xxyy; } st_array[v] = slope; } } /*************************************/ float tilt = 0.; float tilt_morning = st_array[1]; float tilt_evening = -st_array[0]; float n_x00 = (map->GetZ(x+1,y) - map->GetZ(x,y)) / (map->GetWidthXPerRaw()/boost); float n_y00 = (map->GetZ(x,y+1) - map->GetZ(x,y)) / (map->GetWidthYPerRaw()/boost); float n_x11 = (map->GetZ(x+1,y+1) - map->GetZ(x,y+1)) / (map->GetWidthXPerRaw()/boost); float n_y11 = (map->GetZ(x+1,y+1) - map->GetZ(x+1,y)) / (map->GetWidthYPerRaw()/boost); float n_x = (n_x00 + n_x11)/2.f; float n_y = (n_y00 + n_y11)/2.f; if (lodshadows) { tilt = tilt_morning + tilt_evening; n_x += tilt; n_y -= sqrt(st_array[0]*st_array[1]) * northboost; if (n_y > -st_array[2]) n_y = -st_array[2]; } float norm = sqrt(n_x*n_x + n_y*n_y + 1.f); float n_x1a = ((-n_x/norm)*127.f*1.0f + 128.f); float n_y1a = ((-n_y/norm)*127.f*1.0f + 128.f); float n_z1a = ((1.f/norm) *127.f*1.0f + 128.f); //std::cout << n_x << ":" << n_x1a << std::endl; float angle = 0.; unsigned char n_x1 = (unsigned char)(n_x1a); unsigned char n_y1 = (unsigned char)(n_y1a*cos(angle) + n_z1a*sin(angle)); unsigned char n_z1 = (unsigned char)(-sin(angle)*n_y1a + n_z1a*cos(angle)); unsigned int xn = x; unsigned int yn = y; if (!hasnewmap) { xn = newmap->GetRawX(map->GetCoordX(x)); yn = newmap->GetRawY(map->GetCoordY(y)); } newmap->SetTupel(xn, yn, n_z1, n_y1, n_x1, 255); //newmap->SetBlue (xn, yn, n_z1); //newmap->SetGreen(xn, yn, n_y1); //newmap->SetRed (xn, yn, n_x1); //newmap->SetAlpha(xn, yn, 255); } } if (hasnewmap) _llMapList()->AddMap(targetname, newmap, NULL, NULL, NULL, NULL); return 1; }
int llExportMeshToVRML::Exec(void) { if (!llTriMod::Exec()) return 0; if (!Used("-filename")) filename = (char *)"map.wrl"; if (!MakeSelection()) return 0; //look for _install_dir: if (_llUtils()->GetValue("_install_dir")) { char *filename_tmp = new char[strlen(filename) + strlen(_llUtils()->GetValue("_install_dir")) + 2]; sprintf_s(filename_tmp, strlen(filename) + strlen(_llUtils()->GetValue("_install_dir")) + 2, "%s\\%s", _llUtils()->GetValue("_install_dir"), filename); filename = filename_tmp; } //Now the VRML-specific part: FILE *fptr; if (fopen_s(&fptr, filename, "w")) { _llLogger()->WriteNextLine(-LOG_ERROR,"Unable to open VRML file '%s'\n", filename); return 0; } fprintf(fptr, "#VRML V2.0 utf8\n"); fprintf(fptr, "DEF MATERIAL Material {\n"); fprintf(fptr, " diffuseColor 1 1 1\n"); fprintf(fptr, "}\n"); fprintf(fptr, "Transform {\n"); fprintf(fptr, " rotation 0.5774 0.5774 0.5774 -2.094\n"); fprintf(fptr, " scale 1 1 1\n"); fprintf(fptr, " children [\n"); fprintf(fptr, " Shape {\n"); fprintf(fptr, " appearance Appearance {\n"); fprintf(fptr, " material USE MATERIAL\n"); if (texname) { fprintf(fptr, " texture ImageTexture {\n"); fprintf(fptr, " url \"%s\"\n", texname); fprintf(fptr, " }\n"); } fprintf(fptr, " }\n"); fprintf(fptr, " geometry IndexedFaceSet {\n"); fprintf(fptr, " creaseAngle 3.1415\n"); fprintf(fptr, " coord Coordinate {\n"); fprintf(fptr, " point [\n"); //Vertices: for (int i=0; i<newpoints->GetN(); i++) { fprintf(fptr, " %f %f %f\n", newpoints->GetX(i), newpoints->GetY(i), newpoints->GetZ(i)); } fprintf(fptr, " ] \n }\n"); //Tex-coords: if (texname) { fprintf(fptr, " texCoord TextureCoordinate {\n"); fprintf(fptr, " point [\n"); for (int i=0; i<newpoints->GetN(); i++) { fprintf(fptr, " %f %f\n", newpoints->GetU(i), newpoints->GetV(i)); } fprintf(fptr, " ] \n }\n"); } fprintf(fptr, " coordIndex [ \n"); for (int i=0; i<newtriangles->GetN(); i++) { fprintf(fptr, " %i %i %i -1 \n", newtriangles->GetPoint1(i), newtriangles->GetPoint2(i), newtriangles->GetPoint3(i)); } fprintf(fptr, " ]\n"); if (texname) { fprintf(fptr, " texCoordIndex [ \n"); for (int i=0; i<newtriangles->GetN(); i++) { fprintf(fptr, " %i %i %i -1 \n", newtriangles->GetPoint1(i), newtriangles->GetPoint2(i), newtriangles->GetPoint3(i)); } fprintf(fptr, " ] \n"); } if (_llUtils()->GetValue("_install_dir")) { delete filename; } fprintf(fptr, " } \n } \n ] \n} \n"); return 1; }
int llActivateVisibleVertices::Exec(void) { if (!llTriMod::Exec()) return 0; int n_rounds = 1; if (Used("-radius")) { n_rounds = 1 + 6; } int v = triangles->GetN(); unsigned int total_steps = n_rounds * v; unsigned int last_step = 0; for (int round=0; round < n_rounds; round++) { for (int i=0; i<v; i++) { int o1 = triangles->GetPoint1(i); int o2 = triangles->GetPoint2(i); int o3 = triangles->GetPoint3(i); unsigned int current_step = (round * v) + i; if ( ((current_step * 100) / total_steps) != last_step) { last_step = (current_step * 100) / total_steps; _llLogger()->WriteNextLine(-LOG_INFO, "%i percent complete", last_step); } for (int j=0; j<points->GetN(); j++) { if (j!=o1 && j!=o2 && j!=o3) { float vx = points->GetX(j) - x; float vy = points->GetY(j) - y; float vz = points->GetZ(j) - z; float s, u, v; float sx = x; float sy = y; float sz = z; if (round == 1) { sx += radius; } else if (round == 2) { sx -= radius; } else if (round == 3) { sy += radius; } else if (round == 4) { sy -= radius; } else if (round == 5) { sz += radius; } else if (round == 6) { sz -= radius; } if (sz < map->GetZ(sx, sy)) { sz = map->GetZ(sx, sy); } if (!points->GetActive(j)) { //skip active points, they don't need to be checked again //because they are visible from "somewhere" if (points->VectorIntersectsWithTriangle(sx, sy, sz, vx, vy, vz, points->GetX(o1), points->GetY(o1), points->GetZ(o1), points->GetX(o2), points->GetY(o2), points->GetZ(o2), points->GetX(o3), points->GetY(o3), points->GetZ(o3), &s, &u, &v)) { points->SetTmpInactive(j); } } } } } points->ClearTmpInactive(); } //rounds return 1; }
int Free() const { return size - Used(); }