Multimodal Large Models and Graphic Reconstruction: From Visual Parsing to Compilable Vector Code

    This article breaks down what it takes for multimodal large models to reconstruct a diagram as compilable vector graphics code, using TikZ as the reference format. It explains why hard structural constraints replace the soft constraints of image captioning, decomposes the required capabilities into pixel-to-primitive extraction, 3D and occlusion reasoning, drawing-order planning, and syntax correctness, and proposes a layered evaluation framework covering compilability, primitive recall, coordinate error, line-style consistency, and occlusion order. Practical engineering recommendations include explicit output contracts, structure-before-code prompting, render-loop validation, divide-and-conquer handling of complex diagrams, regression suites, and reusable template layers.

    1. Where the Problem Starts: Why “Draw What You See” Is Harder Than “Describe What You See”

    In image understanding tasks, producing a natural language description is a soft-constraint problem: as long as the semantics are roughly correct, the wording can be flexible. The moment the goal shifts to “reconstruct a diagram as compilable vector graphics code,” the constraints turn hard. The model must not only identify which geometric elements exist in the image, but also produce exact coordinates, path directions, line styles (solid or dashed), fill regions, and drawing order. A mistake at any single stage shows up in the final render as misalignment, reversed occlusion, or wrong layer coverage.

    TikZ is a typical vehicle for this kind of capability. It describes geometry with coordinates and paths, controls line style and fill through options, and determines stacking order through statement sequence. For a model, this means completing three tasks at once—visual parsing, spatial reasoning, and structured code generation—with all three required to stay consistent with each other.

    2. Capability Breakdown: The Layers Behind a Successful Reconstruction

    2.1 Extracting Geometric Primitives from 2D Pixels

    The model has to abstract continuous pixel regions into primitives such as line segments, rectangles, circles, and polygons, and estimate endpoint coordinates and relative proportions. The core difficulty here is scale normalization: diagrams usually have no axes, so the model must establish its own internal reference frame and keep every primitive on the same scale. Otherwise the result is “locally correct, globally distorted.”

    2.2 Reasoning About 3D Structure and Occlusion

    Diagrams commonly use 2D drawing conventions to represent 3D objects—intersecting lines for volumes, broken lines for hidden edges. The model must decide which line is in front, which is blocked, and whether a given face is visible. An occlusion error translates directly into a wrong drawing order, which renders as “a shape that should be behind covers the one in front.”

    2.3 Planning Layers and Drawing Order

    Vector drawing follows a “later paints over earlier” model, so order is itself semantics. A sound approach is to draw the base and main outlines first, then the hidden auxiliary lines, and finally overlay annotations and emphasis elements. Without explicit order planning, a model tends to draw dashed lines on top of solid ones and break the visual expression.

    2.4 Syntactic Correctness of the Structured Code

    The final output must be accepted by a parser: coordinate syntax, path closure, option syntax, and environment nesting all have to be valid. A syntax error makes the entire block fail to compile—a single-strike failure.

    3. What to Evaluate: From “Does It Look Right” to “Compilable and Semantically Consistent”

    Many evaluations stop at visual similarity judged by eye, which is far from enough. A more rigorous approach scores in layers:

    • Compilability: whether the code compiles on the first attempt is the minimum bar.
    • Primitive recall and position error: whether key primitives are all present, and whether coordinate deviation stays within an acceptable range.
    • Line style and fill consistency: whether solid versus dashed and filled versus hollow are expressed correctly.
    • Occlusion and order correctness: whether the stacking matches the input image.
    • Maintainability: whether the code structure is clear and easy to modify later.

    A schematic evaluation skeleton can be written as follows (it only expresses scoring dimensions and does not refer to any specific interface):

    1. score = w1 * compiles
    2. + w2 * primitive_recall
    3. + w3 * (1 - normalized_coord_error)
    4. + w4 * line_style_consistency
    5. + w5 * occlusion_order_correctness

    The weights can be tuned per use case: teaching demos care more about semantics and order, while engineering drawings care more about coordinate precision and compilability.

    4. Engineering Practices: Getting Usable Results Reliably

    1. State the output contract explicitly in the prompt: fix the coordinate range, units, line style naming, and the requirement that paths be closed, leaving less room for the model to improvise.
    2. Ask for structure before code: have the model list the primitives and stacking order first, then generate code, which noticeably reduces order-related errors.
    3. Add render-loop validation: render the generated code to an image, compare features against the input, and regenerate with the differences attached if it falls short, forming a closed loop.
    4. Divide and conquer complex diagrams: split a complex diagram into sub-diagrams, reconstruct them separately, then compose them by layer, avoiding one overly long generation that collapses syntactically.
    5. Build a regression suite: turn typical diagrams into a fixed regression set and run the layered metrics on every capability iteration, instead of relying on the subjective feeling that it “looks stronger.”
    6. Accumulate a reusable template layer: wrap common primitives into reusable snippets so the model fills in blanks under template constraints, balancing flexibility and stability.

    5. How to Observe Capability Progress

    Progress has moved from handling only simple planar shapes to coping with occlusion, dashed and solid lines, and fill regions. The gains show up in three places: more stable spatial reasoning, more syntax-compliant structured output, and better consistency in long code. To judge whether an intermediate version is genuinely stronger, do not look at a single attractive sample; check whether the overall distribution of layered metrics on the regression set shifts upward, and whether failures move from “syntax collapse” to “detail deviation”—the latter usually signals a more mature stage.

    6. Conclusion

    Reconstructing an image as vector graphics code is a combined exam of multimodal understanding, spatial reasoning, and code generation. The reusable lessons for developers are: constrain the model with an explicit output contract, replace subjective impressions with layered metrics, and build stability into the workflow through render loops and templating. To support batch generation and loop validation, you can build a pipeline on general cloud capabilities such as container platforms, object storage, message queues, and monitoring and alerting, turning evaluation and iteration into a sustainable engineering loop.