WARP *Copy_Warps (WARP *Old) { WARP *New; if (Old != NULL) { New=Create_Warp(Old->Warp_Type); switch (Old->Warp_Type) { case CYLINDRICAL_WARP: POV_MEMCPY(New,Old,sizeof(CYLW)); break; case PLANAR_WARP: POV_MEMCPY(New,Old,sizeof(PLANARW)); break; case SPHERICAL_WARP: POV_MEMCPY(New,Old,sizeof(SPHEREW)); break; case TOROIDAL_WARP: POV_MEMCPY(New,Old,sizeof(TOROIDAL)); break; case CLASSIC_TURB_WARP: case EXTRA_TURB_WARP: POV_MEMCPY(New,Old,sizeof(TURB)); break; case REPEAT_WARP: POV_MEMCPY(New,Old,sizeof(REPEAT)); break; case BLACK_HOLE_WARP: POV_MEMCPY(New,Old,sizeof(BLACK_HOLE)); break; case TRANSFORM_WARP: POV_MEMCPY(New,Old,sizeof(TRANS)); break; // JN2007: Cubic warp case CUBIC_WARP: POV_MEMCPY(New,Old,sizeof(WARP)); break; } New->Next_Warp = Copy_Warps(Old->Next_Warp); if(New->Next_Warp != NULL) New->Next_Warp->Prev_Warp = New; } else { New = NULL; } return(New); }
void *pov_memmove (void *dest, void *src, size_t length) { char *csrc =(char *)src; char *cdest=(char *)dest; if (csrc < cdest && csrc + length >= cdest) { size_t size = cdest - csrc; while (length > 0) { POV_MEMCPY(cdest + length - size, csrc + length - size, size); length -= size; if (length < size) size = length; } } /* I'm not sure if this is needed, but my docs on memcpy say the regions * can't overlap, so theoretically we need to special case this. If you * don't think it's necessary, you can just comment this part out. */ else if (cdest < csrc && cdest + length >= csrc) { char *new_dest = cdest; size_t size = csrc - cdest; while (length > 0) { POV_MEMCPY(new_dest, csrc, length); new_dest += size; csrc += size; length -= size; if (length < size) size = length; } } else { POV_MEMCPY(cdest, csrc, length); } return cdest; }
SPLINE * Copy_Spline(SPLINE * Old) { SPLINE * New; New = (SPLINE *)POV_MALLOC(sizeof(SPLINE), "spline"); New->SplineEntries = (SPLINE_ENTRY *)POV_MALLOC(Old->Number_Of_Entries*sizeof(SPLINE_ENTRY), "spline entry"); POV_MEMCPY(New->SplineEntries, Old->SplineEntries, Old->Number_Of_Entries*sizeof(SPLINE_ENTRY)); New->Max_Entries = Old->Number_Of_Entries; New->Number_Of_Entries = Old->Number_Of_Entries; New->Type = Old->Type; New->Coeffs_Computed = Old->Coeffs_Computed; New->Terms = Old->Terms; New->Cache_Valid = false; // we don't copy the cache so mark it as invalid return New; }
static BICUBIC_PATCH *Copy_Bicubic_Patch(OBJECT *Object) { int i, j; BICUBIC_PATCH *New; int m, h; New = Create_Bicubic_Patch(); /* Do not do *New = *Old so that Precompute works right */ New->Ph_Density = Object->Ph_Density; New->Patch_Type = ((BICUBIC_PATCH *)Object)->Patch_Type; New->U_Steps = ((BICUBIC_PATCH *)Object)->U_Steps; New->V_Steps = ((BICUBIC_PATCH *)Object)->V_Steps; if ( ((BICUBIC_PATCH *)Object)->Weights != NULL ) { New->Weights = (WEIGHTS *)POV_MALLOC( sizeof(WEIGHTS),"bicubic patch" ); POV_MEMCPY( New->Weights, (((BICUBIC_PATCH *)Object)->Weights), sizeof(WEIGHTS) ); } for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { Assign_Vector(New->Control_Points[i][j], ((BICUBIC_PATCH *)Object)->Control_Points[i][j]); } } New->Flatness_Value = ((BICUBIC_PATCH *)Object)->Flatness_Value; Precompute_Patch_Values(New); /* copy the mapping */ for (m = 0; m < 4; m++) { for (h = 0; h < 3; h++) { New->ST[m][h] = ((BICUBIC_PATCH *)Object)->ST[m][h]; } } return (New); }
SPLINE * Copy_Spline(const SPLINE * Old) { SPLINE * New; New = reinterpret_cast<SPLINE *>(POV_MALLOC(sizeof(SPLINE), "spline")); New->SplineEntries = reinterpret_cast<SPLINE_ENTRY *>(POV_MALLOC(Old->Number_Of_Entries*sizeof(SPLINE_ENTRY), "spline entry")); POV_MEMCPY(New->SplineEntries, Old->SplineEntries, Old->Number_Of_Entries*sizeof(SPLINE_ENTRY)); New->Max_Entries = Old->Number_Of_Entries; New->Number_Of_Entries = Old->Number_Of_Entries; New->Type = Old->Type; New->Coeffs_Computed = Old->Coeffs_Computed; New->Terms = Old->Terms; //[JG] flyspray #294, cache is not thread-safe // New->Cache_Valid = false; // we don't copy the cache so mark it as invalid New->ref_count = 1; return New; }
ObjectPtr BicubicPatch::Copy() { int i, j; BicubicPatch *New = new BicubicPatch(); int m; /* Do not do *New = *Old so that Precompute works right */ New->Patch_Type = Patch_Type; New->U_Steps = U_Steps; New->V_Steps = V_Steps; if (Weights != NULL) { New->Weights = reinterpret_cast<BEZIER_WEIGHTS *>(POV_MALLOC( sizeof(BEZIER_WEIGHTS),"bicubic patch" )); POV_MEMCPY( New->Weights, Weights, sizeof(BEZIER_WEIGHTS) ); } for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { New->Control_Points[i][j] = Control_Points[i][j]; } } New->Flatness_Value = Flatness_Value; New->Precompute_Patch_Values(); /* copy the mapping */ for (m = 0; m < 4; m++) { New->ST[m] = ST[m]; } return (New); }
bool ot_read_file(OT_NODE **root, IStream *fd, const OT_READ_PARAM* param, OT_READ_INFO* info) { bool retval, got_eof; int line_num = 0; int tempdepth, tx, ty, tz; int goodreads = 0; int count; bool goodparse = true; DBL brightness; OT_BLOCK bl; OT_BLOCK *new_block; OT_ID id; char normal_string[30], to_nearest_string[30]; char line[101]; memset(&bl, 0, sizeof(OT_BLOCK)); if ( fd != NULL ) { info->Gather_Total.Clear(); info->Gather_Total_Count = 0; while (!(got_eof = fd->getline (line, 99).eof ()) && goodparse) { switch ( line[0] ) { case 'B': // the file contains the old radiosity_brightness value { if ( sscanf(line, "B%lf\n", &brightness) == 1 ) { info->Brightness = brightness; } break; } case 'P': // the file made it to the point that the Preview was done { info->FirstRadiosityPass = true; break; } case 'C': { #if (NUM_COLOUR_CHANNELS == 3) RGBColour tempCol; count = sscanf(line, "C%d %lf %lf %lf %s %f %f %f %f %f %s\n", // tw &tempdepth, // since you can't scan a short &bl.Point[X], &bl.Point[Y], &bl.Point[Z], normal_string, &tempCol.red(), &tempCol.green(), &tempCol.blue(), &bl.Harmonic_Mean_Distance, &bl.Nearest_Distance, to_nearest_string ); bl.Illuminance = ToMathColour(tempCol); #else #error TODO! #endif // TODO FIXME - read Quality and Brilliance if ( count == 11 ) { bl.Bounce_Depth = (short)tempdepth - 1; // normals aren't very critical for direction precision, so they are packed sscanf(normal_string, "%02x%02x%02x", &tx, &ty, &tz); bl.S_Normal[X] = ((double)tx * (1./ 254.))*2.-1.; bl.S_Normal[Y] = ((double)ty * (1./ 254.))*2.-1.; bl.S_Normal[Z] = ((double)tz * (1./ 254.))*2.-1.; bl.S_Normal.normalize(); sscanf(to_nearest_string, "%02x%02x%02x", &tx, &ty, &tz); bl.To_Nearest_Surface[X] = ((double)tx * (1./ 254.))*2.-1.; bl.To_Nearest_Surface[Y] = ((double)ty * (1./ 254.))*2.-1.; bl.To_Nearest_Surface[Z] = ((double)tz * (1./ 254.))*2.-1.; bl.To_Nearest_Surface.normalize(); line_num++; new_block = reinterpret_cast<OT_BLOCK *>(POV_MALLOC(sizeof (OT_BLOCK), "octree node from file")); if ( new_block != NULL ) { POV_MEMCPY(new_block, &bl, sizeof (OT_BLOCK)); ot_index_sphere(bl.Point, bl.Harmonic_Mean_Distance * param->RealErrorBound, &id); ot_ins(root, new_block, &id); goodreads++; } else { goodparse = false; // allocation error, better stop now } } break; } default: { // wrong leading character on line, just try again on next line } } // end switch } // end while-reading loop if ( !got_eof || !goodparse ) { ;// TODO MESSAGE PossibleError("Cannot process radiosity cache file at line %d.", (int)line_num); retval = false; } else { if ( goodreads > 0 ) ;// TODO MESSAGE Debug_Info("Reloaded %d values from radiosity cache file.\n", goodreads); else ;// TODO MESSAGE PossibleError("Unable to read any values from the radiosity cache file."); retval = true; } } else { retval = false; } return retval; }
static void project_bounding_slab(int Axis, VECTOR Origin, PROJECT *Project, PROJECT_TREE_NODE **Tree, BBOX_TREE *Node, int proj_thru, PROJECT *proj_proj) { short int i; PROJECT Temp; PROJECT_TREE_LEAF *Leaf; PROJECT_TREE_NODE New; Do_Cooperate(1); /* If the node is totally invisible we are ready. */ if (bbox_invisible(Axis, &Node->BBox, Origin)) { return; } if (Node->Entries) { /* Current object is a bounding object, i.e. a node in the slab tree. */ /* First, Init new entry. */ New.Entries = 0; New.Node = Node; New.Project.x1 = New.Project.y1 = MAX_BUFFER_ENTRY; New.Project.x2 = New.Project.y2 = MIN_BUFFER_ENTRY; /* Allocate temporary memory for node/leaf entries. */ New.Entry = (PROJECT_TREE_NODE **)POV_MALLOC(Node->Entries*sizeof(PROJECT_TREE_NODE *), "temporary tree entry"); /* This is no leaf, it's a node. */ New.is_leaf = false; /* Second, Get new entry, i.e. project bounding slab's entries. */ for (i = 0; i < Node->Entries; i++) { New.Entry[i] = NULL; project_bounding_slab(Axis, Origin, &Temp, &New.Entry[New.Entries], Node->Node[i], proj_thru, proj_proj); /* Use only visible entries. */ if (New.Entry[New.Entries] != NULL) { New.Project.x1 = min(New.Project.x1, Temp.x1); New.Project.x2 = max(New.Project.x2, Temp.x2); New.Project.y1 = min(New.Project.y1, Temp.y1); New.Project.y2 = max(New.Project.y2, Temp.y2); New.Entries++; } } /* If there are any visible entries, we'll use them. */ if (New.Entries > 0) { /* If there's only one entry, we won't need a new node. */ if (New.Entries == 1) { *Tree = New.Entry[0]; *Project = New.Project; } else { /* Allocate memory for new node in the light tree. */ *Tree = (PROJECT_TREE_NODE *)POV_MALLOC(sizeof(PROJECT_TREE_NODE), "light tree node"); **Tree = New; /* Allocate memory for node/leaf entries. */ (*Tree)->Entry = (PROJECT_TREE_NODE **)POV_MALLOC(New.Entries*sizeof(PROJECT_TREE_NODE *), "light tree node"); POV_MEMCPY((*Tree)->Entry, New.Entry, New.Entries*sizeof(PROJECT_TREE_NODE *)); *Project = New.Project; } } /* Get rid of temporary node/leaf entries. */ POV_FREE(New.Entry); } else { /* Current object is a normal object, i.e. a leaf in the slab tree. */ /* If object doesn't cast shadows we can skip it. */ if (!Test_Flag((OBJECT *)Node->Node, NO_SHADOW_FLAG)) { /* Project object onto light source. */ project_object(Project, (OBJECT *)Node->Node, Axis, Origin, proj_thru, proj_proj); /* Is the object visible? */ if ((Project->x1 <= Project->x2) && (Project->y1 <= Project->y2)) { /* Allocate memory for new leaf in the light tree. */ *Tree = (PROJECT_TREE_NODE *)POV_MALLOC(sizeof(PROJECT_TREE_LEAF), "light tree leaf"); /* Init new leaf. */ Leaf = (PROJECT_TREE_LEAF *)(*Tree); Leaf->Node = Node; Leaf->Project = *Project; /* Yes, this is a leaf. */ Leaf->is_leaf = true; } } } }