CGAL Reading and Writing OBJ Texture - cgal

Hoping someone could please provide a snippet to read and write OBJ files with CGAL including normals and UV.
The only way I can think of is to write a reader and writer.
Is there a simple way to extend or re-use the existing reader and writer?
Appreciate any guidance.
Bare minimum example. mesh-in.obj contains vt records, mesh-out.obj does not.
Mesh mesh;
CGAL::IO::read_polygon_mesh("mesh-in.obj", mesh);
CGAL::IO::write_polygon_mesh("mesh-out.obj", mesh);
Should I parse the vt records from the input OBJ file and append as named parameters?

Related

How to get a halide buffer with data on GPU?

I'm new to halide. Now I have a pointer which points to data on GPU. I want to get a halide buffer from this pointer without copying data. I have searched a lot and found this /halidebuffer-on-gpu . It says using Buffer::device_wrap_native will be helpful. And I have read the docs of itBuffer::device_wrap_nativeBut I'm little confused about what value should I pass to device_interface? docs of device_interface don't help me much.
For device_interface you want to pass either halide_cuda_device_interface(), or halide_opencl_device_interface(), or similar. These methods are all defined in HalideRuntime*.h. Here's the full list:
HalideRuntimeCuda.h: halide_cuda_device_interface();
HalideRuntimeD3D12Compute.h: halide_d3d12compute_device_interface();
HalideRuntimeHexagonDma.h: halide_hexagon_dma_device_interface();
HalideRuntimeHexagonHost.h: halide_hexagon_device_interface();
HalideRuntimeMetal.h: halide_metal_device_interface();
HalideRuntimeOpenCL.h: halide_opencl_device_interface();
HalideRuntimeOpenGL.h: halide_opengl_device_interface();
HalideRuntimeOpenGLCompute.h: halide_openglcompute_device_interface();

itextsharp not working on converted pdf from msoffice applications

I'm very confused, why iTextsharp can't read or get the image from pdf(pdf converted from msword,excel,powerpoint)
Here's what I did, I opened msword file, then convert the msword file to pdf, then read the pdf file using iTextsharp, it doesn't recognize if pdf file has an image or shape.
I also tried from powerpoint to pdf, then read the pdf file, it doesn't read the images also.
Here's the code:
Below the images....EDITED...
This is the image that can't be extracted:
This is the image that I test a while ago that is good, and I don't know why the other image can't be detected, or it errors.
As of now I change the code to this:
But also can't detect its an image on the circle shape.
For pn As Integer = 1 To pc
Dim pg As PdfDictionary = pdfr.GetPageN(pn)
Dim res As PdfDictionary = DirectCast(PdfReader.GetPdfObject(pg.Get(PdfName.RESOURCES)), PdfDictionary)
Dim xobj As PdfDictionary = DirectCast(PdfReader.GetPdfObject(res.Get(PdfName.XOBJECT)), PdfDictionary)
MessageBox.Show("THE ERROR IS HERE, IT BYPASS, SO XOBJ IS NOTHING IN THAT IMAGE")
If xobj IsNot Nothing Then
For Each name As PdfName In xobj.Keys
Dim obj As PdfObject = xobj.Get(name)
If obj.IsIndirect() Then
Dim tg As PdfDictionary = DirectCast(PdfReader.GetPdfObject(obj), PdfDictionary)
Dim type As PdfName = DirectCast(PdfReader.GetPdfObject(tg.Get(PdfName.SUBTYPE)), PdfName)
Dim XrefIndex As Integer = Convert.ToInt32(DirectCast(obj, PRIndirectReference).Number.ToString(System.Globalization.CultureInfo.InvariantCulture))
Dim pdfObj As PdfObject = pdfr.GetPdfObject(XrefIndex)
Dim pdfStrem As PdfStream = DirectCast(pdfObj, PdfStream)
If PdfName.IMAGE.Equals(type) Then
Dim bytes As Byte() = PdfReader.GetStreamBytesRaw(DirectCast(pdfStrem, PRStream))
If (bytes IsNot Nothing) Then
Dim strat As New ImageInfoTextExtractionStrategy()
iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(pdfr, pn, strat)
End If
End If
End If
Next
End If
Next
Why your current code does not find or extract those shapes:
The smiley image and the flower image are completely different in nature: The flower image is a bitmap image stored in the PDF as an /XObject (eXternal Object) of subtype /Image while the smiley is a vector images stored in the PDF as a part of the page content stream as a (not necessarily continuous) sequence of path definition and drawing operations.
Your code only searches for bitmap images stored as external objects and it does so in a somewhat convoluted way: It first scans for image xobjects using lowlevel methods, and only if it finds such a xobject, it employs the iText highlevel extraction capabilities. If it started out using only the iText image extraction capabilities, it would be less complex, and at the same time it would also recognize inlined bitmap images.
You might want to look at the iText in Action — 2nd Edition chapter 15 Webified iTextSharp Examples, especially ExtractImages.cs which utilizes MyImageRenderListener.cs for this. While inspiration by that code could improve your current code, it won't yet help you with your issue at hand, though.
What you have to do to find or extract the shapes using iText:
Unfortunately your question is not entirely clear on what you actually are trying to achieve.
Do you merely need to detect whether there is some image (bitmap or vector graphic) on some page?
Do you need some information on the image, e.g. size or position on the page?
Or do you actually want to extract the image?
While these objectives can easily be implemented for bitmap graphics using the afore mentioned iText highlevel extraction capabilities, they are fairly difficult to fulfill for vector graphics.
For generic PDFs they are virtually impossible to implement because the drawing operations for an individual figure need not be together, and even worse, the drawing operations for different figures on the same page, for underlines on the page, and for other graphic effects might even be mixed in one big heap of operations in seemingly random order.
In your case, though, you have one advantage: Office seems to properly tag the figures in the PDF. This at least makes detection of the number of different (i.e. differently tagged) vector graphics on a page easy and also allows for the differentiation which drawing operation belongs to which figure.
Thus, here some pointers on how to achieve the goals mentioned above for PDFs tagged like your sample PDF. As I'm not using VB myself, I don't have sample code. But as your sample code shows that you already know how to follow object references and how to interpret PDF object information, these pointers should suffice to show the way.
1. Detecting whether there is some image on some page.
As the page content is tagged, it suffices to scan the structure hierarchy starting from the /StructTreeRoot entry in the document catalogue (use PdfReader.Catalog, select the value of PdfName.STRUCTTREEROOT in it, and dig into it).
E.g. for page 1 (in PDF object 4 0) of your sample (with the "1233" at the top and the smiley below) you'll find an array with dictionaries:
<<
/Pg 4 0 R
/K [0]
/S /P
/P 24 0 R
>>
and
<<
/Pg 4 0 R
/K [1]
/Alt ()
/S /Figure
/P 22 0 R
>>
each of which references the page (/Pg 4 0 R). The first one is of type /P, a paragraph (your "1233"), and the second one is of type /Figure, a figure (your smiley). The presence of the second element indicates the presence of a figure on the page. Thus, the goal 1 is achieved already with these data.
(For details cf. the PDF specification ISO 32000-1:2008 section 14.7 and 14.8.)
2. Retrieving some information on the image, e.g. size or position on the page.
For this you have to extract the graphics operators responsible for creating the figure in question. As it is tagged, you have to extract the operators in a marked content block associated with the marked content ID given by /K [1] in the /Figure dictionary above, i.e. 1.
In the content stream you'll find this:
/P <</MCID 1>> BDC 0.31 0.506 0.741 rg
108.6 516.6 m
108.6 569.29 160.18 612 223.8 612 c
287.42 612 339 569.29 339 516.6 c
339 463.91 287.42 421.2 223.8 421.2 c
160.18 421.2 108.6 463.91 108.6 516.6 c
h
f*
[...]
108.6 516.6 m
108.6 569.29 160.18 612 223.8 612 c
287.42 612 339 569.29 339 516.6 c
339 463.91 287.42 421.2 223.8 421.2 c
160.18 421.2 108.6 463.91 108.6 516.6 c
h
S
EMC
This section between BDC for /MCID 1 and EMC contains the graphics operations you seek. If you want to get some information on the figure they represent, you have to analyze them.
This is a very low-level view on all this and one might whish for a higher level API to retrieve this.
iText does have a high level API for the analogous operations for text and bitmap image processing using the parser namespace class PdfReaderContentParser together with some apropos RenderListener implementation like your ImageInfoTextExtractionStrategy. Unfortunately, though, PdfReaderContentParser does not yet properly pre-process the vector graphics related operators.
To do this with iText, therefore, you either have to extend the underlying PdfContentStreamProcessor to add the missing pre-processing (which is do-able as that parser class is implemented using separate listeners for the individual operations, and you can easily register new listeners for the graphics operators); or you have to retrieve the page content and parse it yourself.
3. Extracting the image.
As the vector images inside a PDF use PDF specific vector graphics operators, you first have to decide in which format you want to export the image. Unless you are interested in the raw PDF operators, you will most likely require some library helping you to create a file in the desired format.
Once that is decided, you first extract the graphics operators in question as explained before and then feed them to that library to create an exportable image of your choice.

How does Jeff Lamarches script binds the texture to objects [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Loading model using Jeff Lamarches script
Guys this might sound very newbie question anyway i'm very new to GLKit and OpenGL
I'm using the Jeff Lamarches scipt from here (https://github.com/jlamarche/iOS-OpenGLES-Stuff) to generate Objective C header file from Blender.
Let say I've created a cube and did UV mapping in Blender using some image suppose image.png.
So basically I would like to understand where in the header the information about the mapping of the texture on the 3D model is kept ? Because I see only the vertex coordinates and normals in it.
In his examples of the MeshVertexModel is a three field array i.e.
...
{/*v:*/{-0.351562, 0.828125, -0.242188}, /*n:*/{-0.183599, 0.982971, 0.005310}, /*t:*/{0.954205, 0.958702}},
...
But all I'm getting from generated header file is in following format
...
{/*v:*/{-0.351562, 0.828125, -0.242188}, /*n:*/{-0.183599, 0.982971, 0.005310}},
...
Found that similar issue has also Wavefront export, here http://projects.blender.org/tracker/index.php?func=detail&aid=30317&group_id=9&atid=498 in 2.63 Blender.
Just replacing the uv_layer = me.uv_textures.active.data by uv_layer = me.tessface_uv_textures.active.data helped to have generated texture coordinates.
Update : For the sphere and cube the script does not work normally, i.e. for Cube it does generate no vertices and for sphere it does generate the vertice of a circle, for other complecated objectes the patch works and generates all the data correctly.

Tesselation/CGR Details from CATPart_CATIA_API

I need to read the tessellation/cgr/visualisation details from a CATIA V5R18 Part file using CATIA V5R18 API.
Visualisation details such as:
Number of Vertices
Number of Triangles
Number of Strips
Number of Fans
Number of Normal
Bounding Sphere Centre and Radius
These details I have read from .cgr files using CAT3DRep/CATRep/CATSurfacicRep, but I am not able to read the same for .CATPart files.
From .CATPart with the help of CATIVisu I got CAT3DBagRep type, when I queried from PartFeatures. But to get Visualisation details I need CATSurfacicRep.
What interface should I query and from where should I query?
I am not sure about R18 but for R22 and R23 if you have the CAA documentation there is an example located at: C:\Program Files\Dassault Systemes\B23\CAADoc\CAATessellation.edu.
This example code has everything you need to get the tessellation data except normals and bounding spheres. I used this example code when I was teaching myself how to make a tessellated nurbs surface and it was quite useful for testing.

Multithreading a filestream in vb2005

I am trying to build a resource file for a website basically jamming all the images into a compressed file that is then unpacked on the output buffers to the client.
my question is in vb2005 can a filestream be multi threaded if you know the size of the converted file, ala like a bit torrent and work on pieces of the filestream ( the individual files in this case) and add them to the resource filestream when they are done instead of one at a time?
If you need something similar to the torrents way of writing to a file, this is how I would implement it:
Open a FileStream on Thread T1, and create a queue "monitor" for step 2
Create a queue that will be read from T1, but written by multiple network reader threads. (the queue data structure would look like this: (position where to write, size of data buffer, data buffer).
Fire up the threads
:)
Anyway, from your comments, your problem seems to be another one..
I have found something in, but I'm not sure if it works:
If you want to write data to a file,
two parallel methods are available,
WriteByte() and Write(). WriteByte()
writes a single byte to the stream:
byte NextByte = 100;
fs.WriteByte(NextByte);
Write(), on the other hand, writes out
an array of bytes. For instance, if
you initialized the ByteArray
mentioned before with some values, you
could use the following code to write
out the first nBytes of the array:
fs.Write(ByteArray, 0, nBytes);
Citation from:
Nagel, Christian, Bill Evjen, Jay
Glynn, Morgan Skinner, and Karli
Watson. "Chapter 24 - Manipulating
Files and the Registry". Professional
C# 2005 with .NET 3.0. Wrox Press. ©
2007. Books24x7. http://common.books24x7.com/book/id_20568/book.asp
(accessed July 22, 2009)
I'm not sure if you're asking if a System.IO.FileStream object can be read from or written to in a multi-threaded fashion. But the answer in both cases is no. This is not a supported scenario. You will need to add some form of locking to ensure serialized access to the resource.
The documentation calls out multi-threaded access to the object as an unsupported scenario
http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx