~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to release/scripts/addons/io_convert_image_to_mesh_img/import_img.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-05-12 20:02:22 UTC
  • mfrom: (14.2.16 sid)
  • Revision ID: package-import@ubuntu.com-20120512200222-lznjs2cxzaq96wua
Tags: 2.63a-1
* New upstream bugfix release
  + debian/patches/: re-worked since source code changed

Show diffs side-by-side

added added

removed removed

Lines of Context:
194
194
    def bin2(self, image_iter, bin2_method_type="SLOW"):
195
195
      ''' this is an iterator that: Given an image iterator will yield binned lines '''
196
196
 
 
197
      ignore_value = self.__ignore_value
 
198
 
197
199
      img_props = next(image_iter)
198
200
      # dimensions shrink as we remove pixels
199
201
      processed_dims = img_props.processed_dims()
207
209
 
208
210
      # Take two lists  [a1, a2, a3], [b1, b2, b3] and combine them into one
209
211
      # list of [a1 + b1, a2+b2,  ... ] as long as both values are not ignorable
210
 
      combine_fun = lambda a, b: a != self.__ignore_value and b != self.__ignore_value and a + b or self.__ignore_value
 
212
      combine_fun = lambda a, b: a != ignore_value and b != ignore_value and (a + b)/2 or ignore_value
211
213
 
212
214
      line_count = 0
213
215
      ret_list = []
220
222
            del tmp_list[0:2]
221
223
          yield ret_list
222
224
          ret_list = []
223
 
        line_count += 1
 
225
        else:
 
226
          last_line = line
 
227
          line_count += 1
224
228
 
225
229
    def bin6(self, image_iter, bin6_method_type="SLOW"):
226
230
      ''' this is an iterator that: Given an image iterator will yield binned lines '''
276
280
        if not ints:
277
281
          binned_data.append( IGNORE_VALUE )
278
282
        else:
279
 
          binned_data.append( sum(ints) / len(ints) )
 
283
          binned_data.append( sum(ints, 0.0) / len(ints) )
280
284
 
281
285
        base += 6
 
286
 
282
287
      return binned_data
283
288
 
284
289
    def bin6_real_fast(self, raw_data):
499
504
      point_offset += len( last_line ) - last_line.count(None)
500
505
      for z in last_line:
501
506
        if z != None:
502
 
          coords.extend([x*scale_x, 0.0, z])
 
507
          coords.append( (x*scale_x, 0.0, z) )
503
508
          coord += 1
504
509
        x += 1
505
510
 
531
536
        x = 0
532
537
        for z in dtm_line:
533
538
          if z != None:
534
 
            coords.extend( [x*scale_x, y_val, z] )
 
539
            coords.append( (x*scale_x, y_val, z) )
535
540
            coord += 1
536
541
          x += 1
537
542
 
549
554
 
550
555
          # Common case: we can create a square face
551
556
          if none_val == 0:
552
 
            faces.extend( [
 
557
            faces.append( (
553
558
              previous_point_offset,
554
559
              previous_point_offset+1,
555
560
              point_offset+1,
556
561
              point_offset,
557
 
              ] )
 
562
              ) )
558
563
            face_count += 1
559
564
          elif none_val == 1:
560
565
            # special case: we can implement a triangular face
579
584
        last_line = dtm_line
580
585
 
581
586
      me = bpy.data.meshes.new(img_props.name()) # create a new mesh
582
 
 
583
 
      me.vertices.add(len(coords)/3)
584
 
      me.vertices.foreach_set("co", coords)
585
 
 
586
 
      me.faces.add(len(faces)/4)
587
 
      me.faces.foreach_set("vertices_raw", faces)
 
587
      #from_pydata(self, vertices, edges, faces)
 
588
      #Make a mesh from a list of vertices/edges/faces
 
589
      #Until we have a nicer way to make geometry, use this.
 
590
      #:arg vertices:
 
591
      #   float triplets each representing (X, Y, Z)
 
592
      #   eg: [(0.0, 1.0, 0.5), ...].
 
593
      #:type vertices: iterable object
 
594
      #:arg edges:
 
595
      #   int pairs, each pair contains two indices to the
 
596
      #   *vertices* argument. eg: [(1, 2), ...]
 
597
      #:type edges: iterable object
 
598
      #:arg faces:
 
599
      #   iterator of faces, each faces contains three or more indices to
 
600
      #   the *vertices* argument. eg: [(5, 6, 8, 9), (1, 2, 3), ...]
 
601
      #:type faces: iterable object
 
602
      me.from_pydata(coords, [], faces)      
 
603
 
 
604
      # me.vertices.add(len(coords)/3)
 
605
      # me.vertices.foreach_set("co", coords)
 
606
      # me.faces.add(len(faces)/4)
 
607
      # me.faces.foreach_set("vertices_raw", faces)
588
608
 
589
609
      me.update()
590
610