]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx
#3507 Undo and Redo Meshes
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkCreateMeshFromPoints.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbcreaVtkCreateMeshFromPoints.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include "vtkTriangleStrip.h"
8 #include "vtkTriangle.h"
9 #include <vtkMath.h>
10
11 namespace bbcreaVtk
12 {
13
14 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,CreateMeshFromPoints)
15 BBTK_BLACK_BOX_IMPLEMENTATION(CreateMeshFromPoints,bbtk::AtomicBlackBox);
16 //===== 
17 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
18 //===== 
19 void CreateMeshFromPoints::Process()
20 {
21
22 // THE MAIN PROCESSING METHOD BODY
23 //   Here we simply set the input 'In' value to the output 'Out'
24 //   And print out the output value
25 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
26 //    void bbSet{Input|Output}NAME(const TYPE&)
27 //    const TYPE& bbGet{Input|Output}NAME() const 
28 //    Where :
29 //    * NAME is the name of the input/output
30 //      (the one provided in the attribute 'name' of the tag 'input')
31 //    * TYPE is the C++ type of the input/output
32 //      (the one provided in the attribute 'type' of the tag 'input')
33
34 //    bbSetOutputOut( bbGetInputIn() );
35 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
36
37                 std::vector<double> lstX                = bbGetInputLstX();
38                 std::vector<double> lstY                = bbGetInputLstY();
39                 std::vector<double> lstZ                = bbGetInputLstZ();
40                 std::vector<int> lstIndexs              = bbGetInputLstIndexs();
41                 double pointsCentroid[3];
42                 if ( (lstIndexs.size()<1) || (lstX.size()==0) || (lstX.size()!=lstY.size()) || (lstY.size()!=lstZ.size()) )
43                 {
44                         printf("Warning! CreateMeshFromPoints::Process: List of points X Y Z  and LstIndexes is not correct\n");
45                         bbSetOutputOut(NULL);
46                 } else  {
47                         int ii,sizeSegment1,sizeSegment2;
48                         int endSegment;
49 //                      vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
50                         if (points!=NULL) points->Delete();
51                         points = vtkPoints::New();
52                         int i,sizeLstX  =       lstX.size();
53                         for (i=0;i<sizeLstX;i++)
54                         {
55                                 points->InsertNextPoint(lstX[i],lstY[i],lstZ[i]);
56                                 pointsCentroid[0] += lstX[i];
57                                 pointsCentroid[1] += lstY[i];
58                                 pointsCentroid[2] += lstZ[i];
59                         } // for i
60                         pointsCentroid[0] /= sizeLstX;
61                         pointsCentroid[1] /= sizeLstX;
62                         pointsCentroid[2] /= sizeLstX;
63                         
64                         if ((bbGetInputCloseSurface()==true)  && (lstIndexs.size()>=2) )
65             {   
66                 //check if initial and end points are the same in all splines (splines are in line shape and not U shape)
67                 //to not apply changes because clean polydata will take care of it.
68                                 int count = 0;
69                                 bool differentPoints = false;
70                                 for(i=0; i < lstIndexs.size() && !differentPoints;i++){
71                                         bool sameStart = lstX[count] != lstX[count+lstIndexs[i]-1] && lstY[count] != lstY[count+lstIndexs[i]-1] && lstZ[count] != lstZ[count+lstIndexs[i]-1];
72                                         bool sameEnd = lstX[count] != lstX[count+lstIndexs[i]-1] && lstY[count] != lstY[count+lstIndexs[i]-1] && lstZ[count] != lstZ[count+lstIndexs[i]-1];
73                                         if(!(sameStart && sameEnd)) differentPoints = true;
74                                         count += lstIndexs[i];
75                                 }
76                 //Correct surface normals if needed
77                 if(differentPoints)
78                         {
79                             double pointSurf1[3], pointSurf2[3], pointSurf3[3];
80                             double vect1[3], vect2[3];
81                             double surfNormal[3], vectorCenter[3];
82                             double dotNormalSurf = 0;
83                             for(int pIndex = 0; pIndex < lstIndexs[0]-1; pIndex++)
84                             {
85                                     pointSurf1[0] = lstX[pIndex];
86                                     pointSurf1[1] = lstY[pIndex];
87                                     pointSurf1[2] = lstZ[pIndex];
88                                     vtkMath::Subtract(pointsCentroid, pointSurf1, vectorCenter);
89                                     pointSurf2[0] = lstX[pIndex+lstIndexs[1]];
90                                     pointSurf2[1] = lstY[pIndex+lstIndexs[1]];
91                                     pointSurf2[2] = lstZ[pIndex+lstIndexs[1]];
92                                     pointSurf3[0] = lstX[pIndex+1];
93                                     pointSurf3[1] = lstY[pIndex+1];
94                                     pointSurf3[2] = lstZ[pIndex+1];
95                                     vtkMath::Subtract(pointSurf2, pointSurf1, vect1);
96                                     vtkMath::Subtract(pointSurf3, pointSurf1, vect2);
97                                     vtkMath::Cross(vect1, vect2, surfNormal);
98                                     dotNormalSurf += vtkMath::Dot(surfNormal, vectorCenter);
99                             } // for pIndex
100
101                                         if(dotNormalSurf > 0){
102                                                 points->Delete();
103                                                 points = vtkPoints::New();
104                                                 for(int splineI = 0; splineI < lstIndexs.size(); splineI++){
105                                                         for (i=lstIndexs[splineI]-1; i >= 0;i--)
106                                                         {
107                                                                 points->InsertNextPoint(lstX[splineI*lstIndexs[0]+i],lstY[splineI*lstIndexs[0]+i],lstZ[splineI*lstIndexs[0]+i]);
108                                                         } // for i
109                                                 } // for splineI
110                                         } // if dotNormalSurf
111                                 }// if differentPoints
112                         }
113                         //
114                         
115 //                      vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
116                         if (cells!=NULL) cells->Delete();
117                         cells = vtkCellArray::New();
118                         int maxElements;
119                         int maxSegment1,maxSegment2;
120                         int iSeg1,iSeg2;
121                         int iGeneral    =       0;
122                         int     sizeLstIdexes=lstIndexs.size();
123                         for (i=0; i<sizeLstIdexes-1; i++ )
124                         {
125                                 sizeSegment1 = lstIndexs[i];
126                                 sizeSegment2 = lstIndexs[i+1];
127                                 vtkSmartPointer<vtkTriangleStrip> triangleStrip = vtkSmartPointer<vtkTriangleStrip>::New();
128                                 triangleStrip->GetPointIds()->SetNumberOfIds(sizeSegment1+sizeSegment2);
129                                 maxElements=sizeSegment1;
130                                 if (maxElements<sizeSegment2) maxElements=sizeSegment2;
131                                 maxSegment1     = iGeneral+sizeSegment1;
132                                 maxSegment2     = iGeneral+sizeSegment1+sizeSegment2;
133                                 iSeg1           = iGeneral;
134                                 iSeg2           = iGeneral+sizeSegment1;
135                                 for (ii=0; ii<maxElements; ii++)
136                                 {
137                                         triangleStrip->GetPointIds()->SetId(ii*2  ,iSeg1);
138                                         triangleStrip->GetPointIds()->SetId(ii*2+1,iSeg2);
139                                         iSeg1++;
140                                         iSeg2++;
141                         if (iSeg1>=maxSegment1) { iSeg1=maxSegment1-1; }
142                         if (iSeg2>=maxSegment2) { iSeg2=maxSegment2-1; }
143                                 } // for ii 
144                                 iGeneral=iGeneral+sizeSegment1;
145                                 cells->InsertNextCell(triangleStrip);
146                         } //for  LstIndexs
147                         
148                         
149                         if(bbGetInputCloseSurface())
150                         {
151                                 int lastId1 = lstIndexs[0]-1;
152                                 int lastId2 = sizeLstX - 1;
153                                 int firstId2 = sizeLstX - lstIndexs[sizeLstIdexes - 1];
154                                 bool face1open = std::fabs(lstX[0] - lstX[lastId1]) > 0.0001 && std::fabs(lstY[0] - lstY[lastId1]) > 0.0001 && std::fabs(lstZ[0] - lstZ[lastId1]) > 0.0001;
155                                 bool face2open = std::fabs(lstX[firstId2] - lstX[lastId2]) > 0.0001 && std::fabs(lstY[firstId2] - lstY[lastId2]) > 0.0001 && std::fabs(lstZ[firstId2] - lstZ[lastId2]) > 0.0001;
156                                 
157                                 bool altFace1open = std::fabs(lstX[0] - lstX[firstId2]) > 0.0001 && std::fabs(lstY[0] - lstY[firstId2]) > 0.0001 && std::fabs(lstZ[0] - lstZ[firstId2]) > 0.0001;
158                                 bool altFace2open = std::fabs(lstX[lastId1] - lstX[lastId2]) > 0.0001 && std::fabs(lstY[lastId1] - lstY[lastId2]) > 0.0001 && std::fabs(lstZ[lastId1] - lstZ[lastId2]) > 0.0001;
159
160                                 //false = Open Contour
161                                 //true = Closed Contour
162                                 if(!face1open && !face2open)
163                                 {
164 //                                      isClosedCont = true;
165                                         CloseContourSides(lstIndexs, true, true);
166                                 }
167                                 else if(!altFace1open && !altFace2open)
168                                 {
169 //                                      isClosedCont = true;
170                                         CloseContourSides(lstIndexs, false, true);
171                                 }
172                                 else{
173                                         CloseOpenContourSurface(lstIndexs);
174                                 }
175                         }
176                     
177 //                      vtkPolyData *polydata = vtkPolyData::New();
178                         if (polydata!=NULL) polydata->Delete();
179                         polydata = vtkPolyData::New();
180                         polydata->SetPoints(points);
181                         polydata->SetStrips(cells);
182 //                      vtkCleanPolyData *clean=vtkCleanPolyData::New();
183                         if (clean!=NULL) clean->Delete();
184                         clean = vtkCleanPolyData::New();
185                         clean->SetInputData(polydata);
186                         clean->Update();
187 //                      vtkTriangleFilter *triangle = vtkTriangleFilter::New();
188                         if (triangle!=NULL) triangle->Delete();
189                         triangle = vtkTriangleFilter::New();
190                         triangle->SetInputData( clean->GetOutput() );
191                         triangle->Update();
192             bbSetOutputOut( triangle->GetOutput() );
193             //            bbSetOutputOut( clean->GetOutput() );
194                 }// if listXYZ size
195                 //printf("PG CreateMeshFromPoints::Process: End\n");
196 }
197 /**
198 * Closes the sides of the contour
199 * iterates in one way or the other, depending on the order of the points and calculated vectors.
200 * uPointOrder: Points are order in a U shape
201 * lstIndexs: number of points on each spline
202 */
203 void CreateMeshFromPoints::CloseContourSides(std::vector<int> lstIndexs, bool uPointOrder, bool isClosedCont){
204         int     sizeLstIdexes = lstIndexs.size();
205         int sizePoints = bbGetInputLstX().size();
206
207         int firstIndex, end, centroidId, numPointsFace, contraryId;
208         int increment = uPointOrder?1:sizeLstIdexes;
209         double centroid[3];
210         int numProcessFaces = sizeLstIdexes > 1?2:1;
211         for(int facesIdx = 0; facesIdx < numProcessFaces; facesIdx++){
212                 std::fill(std::begin(centroid), std::end(centroid), 0);
213                 if(facesIdx == 0)
214                 {
215                         firstIndex = 0;
216                         numPointsFace = uPointOrder?lstIndexs[0]: sizeLstIdexes;
217                         end = uPointOrder?firstIndex + numPointsFace:sizePoints - lstIndexs[sizeLstIdexes - 1] + 1;
218                         contraryId = sizePoints-1;
219                 }else{
220                         firstIndex = uPointOrder?sizePoints - lstIndexs[sizeLstIdexes-1]:lstIndexs[0]-1;
221                         numPointsFace = uPointOrder?lstIndexs[sizeLstIdexes-1]:sizeLstIdexes;
222                         end = uPointOrder?firstIndex + numPointsFace:sizePoints;
223                         contraryId = 0;
224                 }
225                 if(numPointsFace > 1)
226                 {
227                         bool validCentroid = CalcValidCentroid(centroid, firstIndex, end, increment, numPointsFace);
228                         if(validCentroid)
229                         {
230                                 bool normalOrder    = isPointingCorrectly(firstIndex, firstIndex+increment, centroid, contraryId);
231                                 centroidId          = points->InsertNextPoint(centroid[0], centroid[1], centroid[2]);
232                                 //vtkSmartPointer<vtkTriangleStrip> triangleStrip = vtkSmartPointer<vtkTriangleStrip>::New();
233                                 //triangleStrip->GetPointIds()->SetNumberOfIds(numPointsFace*2 + (!isClosedCont?2:0));
234                                 //int triangleIndex = 0;
235                                 if( normalOrder )
236                 {
237                         int initial = firstIndex;
238                         for(int index = initial; index < end; index+=increment){
239                                                 if(index+increment >= end && !isClosedCont){
240                                                         vtkNew<vtkTriangle> triangle;
241                                                         triangle->GetPointIds()->SetId(0, index);
242                                                         triangle->GetPointIds()->SetId(1, initial);
243                                                         triangle->GetPointIds()->SetId(2, centroidId);
244                                                         cells->InsertNextCell(triangle);
245                                                 }else if(index+increment < end){
246                                                         vtkNew<vtkTriangle> triangle;
247                                                         triangle->GetPointIds()->SetId(0, index);
248                                                         triangle->GetPointIds()->SetId(1, index+increment);
249                                                         triangle->GetPointIds()->SetId(2, centroidId);
250                                                         cells->InsertNextCell(triangle);
251                                                 }
252                                                 /*
253                                                 triangleStrip->GetPointIds()->SetId(triangleIndex,index);
254                                                 triangleStrip->GetPointIds()->SetId(triangleIndex+1,centroidId);//1
255                                                 if(index+increment >= end && !isClosedCont){
256                                                         triangleStrip->GetPointIds()->SetId(triangleIndex+2,initial);//2
257                                                         triangleStrip->GetPointIds()->SetId(triangleIndex+3,centroidId);//3
258                                                 }
259                                                 triangleIndex+=2;
260                                                 */
261                                         }
262                                         //cells->InsertNextCell(triangleStrip);
263                                 } else {
264                                         int initial = firstIndex-1;
265                                         int triangleStripStart = end-1;
266                                         for(int index = triangleStripStart; index > initial; index-=increment){ 
267                                                 if(index-increment <= initial && !isClosedCont){
268                                                         vtkNew<vtkTriangle> triangle;
269                                                         triangle->GetPointIds()->SetId(0, index);
270                                                         triangle->GetPointIds()->SetId(1, triangleStripStart);
271                                                         triangle->GetPointIds()->SetId(2, centroidId);
272                                                         cells->InsertNextCell(triangle);
273                                                 }else if(index-increment > initial){
274                                                         vtkNew<vtkTriangle> triangle;
275                                                         triangle->GetPointIds()->SetId(0, index);
276                                                         triangle->GetPointIds()->SetId(1, index-increment);
277                                                         triangle->GetPointIds()->SetId(2, centroidId);
278                                                         cells->InsertNextCell(triangle);
279                                                 }
280                                         }
281                                 }//if normalOrder
282                         }//if validCentroid
283                 }//if numPointsFace
284         }//for facesIdx
285
286 }
287
288 /**
289 * Checks if the normal from firstPointId, secPointId and centroid points away 
290 * from the vector centroid to contrPointId.
291 * Used to check that the order used to create the new polygons is correct.
292 */
293 bool CreateMeshFromPoints::isPointingCorrectly( int firstPointId, int secPointId, double(&centroid)[3], int contrPointId) {
294
295         double firstPoint[3], secPoint[3], contrPoint[3];
296         points->GetPoint(firstPointId, firstPoint);
297         points->GetPoint(secPointId, secPoint);
298         
299         double firstVect[3], secVect[3], normal[3], contrVect[3];
300         
301         vtkMath::Subtract(firstPoint, centroid, firstVect);
302         vtkMath::Subtract(secPoint, centroid, secVect);
303         
304         points->GetPoint(contrPointId, contrPoint);
305         vtkMath::Subtract(contrPoint, centroid, contrVect);
306         
307         vtkMath::Cross(firstVect, secVect, normal);
308         double dotCalc;
309         dotCalc = vtkMath::Dot(normal, contrVect);
310         
311         return dotCalc<0;
312 }
313
314 /**
315 * Checks if the order of the points represent a curved spline (U shape) or the points resemble a straight spline.
316 * Now it checks the angle between each point and the vector that goes from the last point to the first.
317 *
318 * Previous version checked the curvature between 3 points in the spline, but this created problems when the straight lines
319 * had curves in the middle, increasing the curvature although they are not in the U shape.
320 */
321 bool CreateMeshFromPoints::CheckLinePointOrder(){
322         int sizePoints = bbGetInputLstX().size();
323         std::vector<int> lstIndexs = bbGetInputLstIndexs();
324         double point1[3], point2[3], point3[3];
325         double center[3];
326         double firstAngleSum = 0;
327         double secondAngleSum = 0;
328
329         points->GetPoint(0, point1);
330         points->GetPoint((lstIndexs[0]-1), point3);
331         double firstVect[3];
332         double secVect[3];
333         vtkMath::Subtract(point3, point1, firstVect);
334         for(int i = 0; i < lstIndexs[0]; i++){
335                 points->GetPoint(i, point2);
336                 vtkMath::Subtract(point2, point1, secVect);
337                 firstAngleSum += vtkMath::SignedAngleBetweenVectors(firstVect, secVect, firstVect);
338         }
339         points->GetPoint((sizePoints-lstIndexs[0]), point3);
340         vtkMath::Subtract(point3, point1, firstVect);
341         for(int i = 0; i < sizePoints; i+=lstIndexs.size()){
342                 points->GetPoint(i, point2);
343                 vtkMath::Subtract(point2, point1, secVect);
344                 secondAngleSum += vtkMath::SignedAngleBetweenVectors(firstVect, secVect, firstVect);
345         }
346
347         return firstAngleSum < secondAngleSum;
348 }
349
350 /**
351 * Closes an open contour
352 * lstIndexs: number of points on each spline
353 */
354 void CreateMeshFromPoints::CloseOpenContourSurface(std::vector<int> lstIndexs){
355         bool linePointOrder = CheckLinePointOrder();
356         CloseContourSides(lstIndexs, !linePointOrder, false);
357         CloseContourBottom(!linePointOrder);
358 }
359
360 /**
361 * Calculates centroid and checks if points are collinear.
362 * centroid: array to store calculation
363 * start: start index of points to use
364 * end: end index of points to use
365 * increment: increment to be used in point iteration
366 * numPoints: number of points used to calculate the centroid.
367 * Returns a bool indicating the validity of the centroid calculated.
368 * False = invalid centroid = all points are the same.
369 */
370 bool CreateMeshFromPoints::CalcValidCentroid(double(&centroid)[3], int start, int end, int increment, int numPoints){
371         double currPoint[3] = {}, prevPoint[3] = {}, middlePoint[3] = {}, firstPoint[3] = {};
372         double vector1[3], vector2[3];
373         bool samePoint = true;
374         int splineMidPoint = numPoints/2;
375         bool collinear = true;
376
377         points->GetPoint(start, firstPoint);
378         points->GetPoint(splineMidPoint, middlePoint);
379         vtkMath::Subtract(middlePoint, firstPoint, vector1);
380
381         for(int i = start; i < end; i+=increment){
382                 points->GetPoint(i, currPoint);
383                 if(samePoint && i > start && (currPoint[0] != prevPoint[0] || currPoint[1] != prevPoint[1] || currPoint[2] != prevPoint[2])){
384                         samePoint = false;
385                 }
386
387                 vtkMath::Subtract(currPoint, firstPoint, vector2);
388                 double angle = vtkMath::AngleBetweenVectors(vector1, vector2);
389                 if(angle > 0.0001 && collinear){
390                         collinear = false;
391                 }
392                 
393                 centroid[0] += currPoint[0];
394                 centroid[1] += currPoint[1];
395                 centroid[2] += currPoint[2];
396                 std::copy(std::begin(currPoint), std::end(currPoint), prevPoint);
397         }
398         
399         centroid[0] /= numPoints;
400         centroid[1] /= numPoints;
401         centroid[2] /= numPoints;
402         
403         return !samePoint && !collinear;
404 }
405
406 /**
407 * Closes the bottom of the given countour.
408 * Should only be used when its an open contour.
409 * uPointOrder: points are ordered in U shape
410 */
411 void CreateMeshFromPoints::CloseContourBottom(bool uPointOrder){
412         std::vector<int> lstIndexs = bbGetInputLstIndexs();
413         int sizeLstIdexes = lstIndexs.size();
414         int sizeLstX = bbGetInputLstX().size();
415         
416         vtkSmartPointer<vtkTriangleStrip> triangleStripBottom = vtkSmartPointer<vtkTriangleStrip>::New();
417         triangleStripBottom->GetPointIds()->SetNumberOfIds(sizeLstIdexes*2);
418         
419         double originPoint[3];
420         points->GetPoint(0, originPoint);
421         int middleMeshPoint = uPointOrder?lstIndexs[0]/2:lstIndexs[0]*sizeLstIdexes/2;
422         
423         bool normalOrder = isPointingCorrectly(uPointOrder?lstIndexs[0]-1:sizeLstX-lstIndexs[0], uPointOrder?lstIndexs[0]:1, originPoint, middleMeshPoint);
424         
425         int triangleIndex = 0, currentId = 0, nextId = 0;
426         for(int splineIndex = 0; splineIndex < sizeLstIdexes;splineIndex++){
427                 nextId = uPointOrder?currentId + lstIndexs[splineIndex] - 1:sizeLstX - sizeLstIdexes + splineIndex;
428                 if(normalOrder)
429                 {
430                         triangleStripBottom->GetPointIds()->SetId(triangleIndex, currentId);
431                         triangleStripBottom->GetPointIds()->SetId(triangleIndex+1, nextId);
432                 }
433                 else{
434                         triangleStripBottom->GetPointIds()->SetId(triangleIndex, nextId);
435                         triangleStripBottom->GetPointIds()->SetId(triangleIndex+1, currentId);
436                 }
437                 currentId = uPointOrder?nextId + 1: splineIndex+1;
438                 triangleIndex+=2;
439         }
440         cells->InsertNextCell(triangleStripBottom);
441 }
442
443 //===== 
444 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
445 //===== 
446 void CreateMeshFromPoints::bbUserSetDefaultValues()
447 {
448
449 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
450 //    Here we initialize the input 'In' to 0
451 //   bbSetInputIn(0);
452         bbSetInputCloseSurface(false);
453         points          = NULL;
454         cells           = NULL;
455         polydata        = NULL;
456         clean           = NULL;
457         triangle        = NULL;
458 }
459 //===== 
460 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
461 //===== 
462 void CreateMeshFromPoints::bbUserInitializeProcessing()
463 {
464
465 //  THE INITIALIZATION METHOD BODY :
466 //    Here does nothing 
467 //    but this is where you should allocate the internal/output pointers 
468 //    if any 
469
470   
471 }
472 //===== 
473 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
474 //===== 
475 void CreateMeshFromPoints::bbUserFinalizeProcessing()
476 {
477
478 //  THE FINALIZATION METHOD BODY :
479 //    Here does nothing 
480 //    but this is where you should desallocate the internal/output pointers 
481 //    if any
482   
483 }
484 }
485 // EO namespace bbcreaVtk
486
487